Reputation: 233
I am using the jQuery dataTable library, and am having an issue. I have some event handlers that allow for table cell values to change. After such a change occurs, I then click on the column header for the column with the newly changed data. It resorts all the rows, but the row with the new data is still sorted according to it's original value when I clicked on that column the first time. Below are the two functions I am using.
So, fnDraw() is not having the desired effect.
//called once, after page load completes
function drawTable()
{
$('#mytable').dataTable({"bFilter": false,
"bSort": true,
"bInfo": false,
"bPaginate": false,
"bDestroy": true});
}
//called each time a table cell value is changed
function initTable()
{
var oTable = $('#mytable').dataTable();
oTable.fnDraw();
//fnDraw is not having the desired effect
}
Upvotes: 1
Views: 2906
Reputation: 233
I found a live example from the DataTables website, they have an example that directly deals with this sort of problem. Plus, they show how to do live sorting for select lists and inputs with both text and numbers.
http://www.datatables.net/examples/plug-ins/dom_sort.html
If there is a better answer, I would be glad to take a look. Currently, I feel their example is the way to go.
Upvotes: 1
Reputation: 381
In addition to @jacouh's solution of re-initializing the table, try setting "bStateSave": true
in the DataTables options as well. This should have DataTables set a cookie to remember a user's sorting preferences.
Upvotes: 0
Reputation: 8741
Have you tested also:
//called each time a table cell value is changed
function initTable()
{
var oTable = $('#mytable').dataTable({"bFilter": false,
"bSort": true,
"bInfo": false,
"bPaginate": false,
"bDestroy": true});
oTable.fnDraw();
//fnDraw is not having the desired effect
}
?
Upvotes: 0