Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change table tr TD value change query

I have a table and want to change the data-title="Status" value.

For Example : data-status text is DataSubmission means need to change the value as ‘Inprogress’

Below the code please check:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$("#cpC_gvSearchResult tr td:contains('DataSubmission')").html("In Progress");

If data-title="Status – text value is empty or blank we want to change the value ‘Available’

$("#cpC_gvSearchResult tr td:contains('')").html("Available");

This the code :

<table class="inbox appList" cellspacing="0" data-openonpick="False" id="cpC_gvSearchResult" style="border-collapse:collapse;">
   <thead>
      <tr class="inboxHeader">
         <th data-field="ApplicationId" scope="col"> Id</th>
         <th data-field="ApplicantFirstName" scope="col">First Name</th>
         <th data-field="CurrentQueue" scope="col">Status</th>
      </tr>
   </thead>
   <tbody>
      <tr class="inboxRow closedApp">
         <td class="inboxCol" data-title="Application Id">1</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">DataSubmission</td>
      </tr>
      <tr class="inboxAltRow closedApp">
         <td class="inboxCol" data-title="Application Id">2</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">&nbsp;</td>
      </tr>
      <tr class="inboxRow closedApp">
         <td class="inboxCol" data-title="Application Id">3</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">DataSubmission</td>
      </tr>
      <tr class="inboxAltRow closedApp">
         <td class="inboxCol" data-title="Application Id">4</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">&nbsp;</td>
      </tr>
   </tbody>
</table>

Jquery:

var rowCount = $("#cpC_gvSearchResult tr").length;
alert(rowCount);
for(var i = 1; i < rowCount; i++)
{
  var status = $("#cpC_gvSearchResult tr").find("td:eq(3)").text();
  if(status =="DataSubmission" )
  {
     $("#cpC_gvSearchResult tr td:contains('DataSubmission')").html("In Progress");
  }
  else
  {
     $("#cpC_gvSearchResult tr td:contains('')").html("Available");
  }
    
}

Live:Demo

>Solution :

A bit unclear what you want to do or why . But here’s a solution.

const tdStatusCols = $("table tbody td[data-title='Status']")
$(tdStatusCols).each(function() {
  const statusText = $(this).text().trim()
  if ( statusText === 'DataSubmission' ) {
      $(this).text("In Progress" )
 } else if (  statusText === '' ) {
     $(this).text("Available" )
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="inbox appList" cellspacing="0" data-openonpick="False" id="cpC_gvSearchResult" style="border-collapse:collapse;">
   <thead>
      <tr class="inboxHeader">
         <th data-field="ApplicationId" scope="col"> Id</th>
         <th data-field="ApplicantFirstName" scope="col">First Name</th>
         <th data-field="CurrentQueue" scope="col">Status</th>
      </tr>
   </thead>
   <tbody>
      <tr class="inboxRow closedApp">
         <td class="inboxCol" data-title="Application Id">1</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">DataSubmission</td>
      </tr>
      <tr class="inboxAltRow closedApp">
         <td class="inboxCol" data-title="Application Id">2</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">&nbsp;</td>
      </tr>
      <tr class="inboxRow closedApp">
         <td class="inboxCol" data-title="Application Id">3</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">DataSubmission</td>
      </tr>
      <tr class="inboxAltRow closedApp">
         <td class="inboxCol" data-title="Application Id">4</td>
         <td class="inboxCol" data-title="Entity / Individual First Name" data-sid="al_Cust05">Dummy Name</td>
         <td class="inboxCol" data-title="Status" data-sid="al_ApplicantFirstName">&nbsp;</td>
      </tr>
   </tbody>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading