0

I used jquery data table for sorting. It works fine under normal condition. If i changed the value in run time, the sorting is not working.

This is my table data

        <table width="94%" cellpadding="2" cellspacing="1" class="tablehead" id="pls-batting">
    <thead>     
    <tr class="tab_head" align="right" id="pls-play" >
    <th width="44" align="center" ># No </th>
    </tr>
    </thead>
    <tbody>
    <tr  id="116706">
    <td align="left" id='1' >test</td>
    </tr>
    <tr id="116707">
    <td align="left" id='2'>bbb</td>
    </tr>
    <tr id="116708">
    <td align="left" id='3' >xxx</td>
    </tr>
    </tbody>
    </table>

Jquery method used for sorting is :

 $(document).ready(function() {

   $('#pls-batting').dataTable( {

            } );
  } );

By clicking the '# No' head the corresponding column displayed in asc and desc order respectively. These TD values will be changed onload by using

        document.getElementById(3).innerHTML = 'something';

So as a result the 3rd column value is 'something'. So sorting will be done by this values. But it is not working.

It takes the old values. Please help me. Thanks

2
  • 1
    You need to show more code if you like to get some help. Commented Feb 8, 2012 at 7:50
  • Now i edited my explanation. Please let me know if you need more clarification. In jquery .live() will take the run time value (i.e if we changed the values on click then it will be taken in to account. ) Similarly is there any way to workout the datatable sorting. Commented Feb 8, 2012 at 9:52

1 Answer 1

1

In DataTables, you should not update content of HTML cell. DT uses internal JavaScript array structure for searching/sorting and this cell is only a display value.

To update some cell you will need to use DT fnUpdate function see http://datatables.net/api#fnUpdate. Example of updating cell in the table is:

var oTable = $('#example').dataTable(); oTable.fnUpdate( 'New content', 10, 3 );

Note that cells are referenced by row/cell positions. If you don't know row/cell position then you can use http://datatables.net/api#fnGetPosition function to find position of TR with id 3 and use this info to update cell data using the fnGetData function (you can find example on the http://datatables.net/api#fnGetPosition)

Jovan

Sign up to request clarification or add additional context in comments.

1 Comment

I am having checkboxes in cell, I want to sort it on checked/unchecked, datatable is not differentiating checked or unched while sorting, so I added data-sort attribute, and onCheck/uncheck I am changing data-sort value in DOM, it is getting changed, but sort is not getting applied even at last line I also dt3.draw()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.