Row Count

Row Count

steegejesteegeje Posts: 5Questions: 1Answers: 0

is there a was to update the row count on a datatable? i was using the .remove() to take off rows and also used fnDeleteRow();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin

    You need to use the DataTables API (see the FAQs) rather than DOM or jQuery methods to manipulate the table's content, otherwise DataTables doesn't know that things have changed. row().remove() or the legacy fnDeleteRow method should do it.

    If not, then please link to a test case showing the issue.

    Allan

  • steegejesteegeje Posts: 5Questions: 1Answers: 0

    so im not 100% sure how to delete a specific row but this is what I am using
    var oTable = $('#tbRAP').dataTable();
    oTable.fnDeleteRow(0);

    we are on version 1.94

  • steegejesteegeje Posts: 5Questions: 1Answers: 0

    so im not sure what I was doing wrong but it does remove the row and update now, so how would I specify what row I am wanting to delete, it looks like I should be using DT_RowId. Right now I am looping through the rows using jquery, and if a successful save is made I am removing that row, so this is my table

        oTable = $('#tbRAP').dataTable(
                  {
                      "aaSorting": [[0, "desc"]],
                      "bJQueryUI": true,
                      "iDisplayLength": 25,
                      "sPaginationType": "full_numbers",
                      "bInfo": true,
                      "aaData": eval(msg.d),
                      "aoColumns": [
                                         {
                                             "sTitle": "ID #", "mData": "ProjectID", "sClass": "dtLabel labelbold", "sWidth": "20px", "mRender": function (ProjectID, type, row) {
                                                 return "<a href=javascript:LookUpProject('" + ProjectID + "')>" + row.ProjectDisplayID + "</a> <label class='ProjectID GridHiddenColumn'>" + ProjectID + "</label>";
                                             }
                                         },
    

    (I but some collumns out for brevity. so here is the code I am using to loop through, which I am guessing is the issue, I am guessing I don't have access to that id?

    var table = $(".StrategyReview");
    var i = 0;
    var k = 0;
    var rowCount = $(".StrategyReview").attr('rows').length;
    table.find('tr').each(function () {
    if (i >= 1 && i != rowCount - k) {

                      var ProjectID = $(this).find(".ProjectID").text();
    
                                  UpdateRiskReview(ProjectID, DecisionValue, Comments, EmpID, $(this));
                              }
    
    
                  }
                  i++;
              });
          }//end function save strategy
    
  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin
    Answer ✓

    I would suggesting using 1.10.x - 1.9 is no longer supported. For 1.10 you use row().remove() and just pass in the row node you want to remove.

    Allan

  • steegejesteegeje Posts: 5Questions: 1Answers: 0

    unfortunately moving up is not option right now

  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin

    You should be able to pass the node into fnDeleteRow I think rather than an index.

    Allan

  • steegejesteegeje Posts: 5Questions: 1Answers: 0

    so If I call oTable.fnDeleteRow(tr); it does delete a row, not the one expected and it seems count doesn't update. Thanks for all the help on this, I think I might just rebuild the table until we can update the version we are using

This discussion has been closed.