Reputation: 9
My DataTable is set up to allow users to select a row. On the side of the table, I have "Up" and "Down" buttons that will allow the user to move the rows of data on the table. To actually move the rows, I need to know the row number of the selected node and the most apparently obvious way to do this was by using fnGetPosition(). However, when I use FireBug to debug the code, it tells me that fnGetPosition() isn't a function.
This is my function that is called when the Up button is pressed:
function moveRowUp()
{
var table = TableTools.fnGetInstance('firstConditionalTable');//Initialize table as an instance of TableTools
var rows = $("#firstConditionalTable tr");//Making a jQuery objecet of the tr elements in the table
var row = table.fnGetSelected();//fnGetSelected returns an array of all selected nodes. row should be assigned an array.
var index = table.fnGetPosition(row[0]);//Get row number of selected node. FireBug tells me that table.fnGetPosition is not a function.
alert(index);//Testing purposes
rows.eq(index).insertBefore(rows.eq(index - 1));//Does the actual moving up
}
If anyone sees any issues, any help would be greatly appreciated.
Upvotes: 1
Views: 2669
Reputation: 5453
table.fnGetPosition(row[0]);//Get row number of selected node. FireBug tells me that table.fnGetPosition is not a function
And it is correct - here you have 'table' as the TableTools instance, which fnGetPosition a the DataTable method ( http://datatables.net/api ). It is rare that you would want to use fnGetPosition - it gives you the internal index of the data in the DataTables cache, not the position in the table.
What you might want is this API method: http://datatables.net/plug-ins/api#fnGetAdjacentTr to give you the next or previous TR element - taking into account sorting, filtering etc. However remember that you can't just use DOM methods with DataTables since its internal sorting would override what manipulate you make - see http://datatables.net/faqs#append
Upvotes: 1