Hello,
I want to let the user the option to add a row after particular row(specified by index after selection).
The function fnAddData add rows just to the end of the table.
Ordering in DataTables is done by using it's sorting functions. Therefore if you wish to insert a new row just after another one in the table you need to take account of this in your sorting.
Take a look at this discussion which considers this: http://datatables.net/forums/comments.php?DiscussionID=227
Okay - without sorting then the order is entirely defined by the 'aiDisplayMaster' (pre filtering) and 'aiDisplay' (post filtering) arrays in DataTables' settings object (typically called oSettings - can be retrieved by fnSettings()). These variables are arrays of indexes which point to the data in the aoData array, and define the order that this data should be output.
What you could do is move the contents of these arrays around as you require (which is exactly how sorting works in DataTables), and then draw the table (fnDraw()).
Hi All,
I know this thread is old but I have code something to add a row in the middle of the table based on this thread. After executing the code I am showing below aiDisplay, aiDisplayMaster and aoData have the correct data on them, the problem is that nothing changes when calling fnDraw. Any thoughts?
[code]
/**
* Inserts the newly created quote after the affected row.
* @param {Object} iForm form used to create the quote
* @param {Object} insertedId inserted quote's id
*/
function insertNewQuoteInTable(iForm, insertedId){
var oDisplay = oTable.dataTableSettings[0].aiDisplay;
var oDisplayMaster = oTable.dataTableSettings[0].aiDisplayMaster;
var oData = oTable.dataTableSettings[0].aoData;
var affectedRowNbr = -1;
var COLUMN_WITH_ROW_ID = 4;
var ind = 0;
//look for affected row number
while (affectedRowNbr==-1 && ind','>I'),
iForm.price, ' ', iForm.quantity, ' ', ' ', ' ', ' ', aData[12], iForm.sequence];
This plugin is so great, its like I dont have to compromise on anything!! I have the same doubt as above tho, I have disabled sorting and I want to add rows in the middle of the table. Is this possible? Since this post is really old, I want to confirm, that a solution has not already been found so I dont reinvent the wheel.. ! cheers
Replies
Ordering in DataTables is done by using it's sorting functions. Therefore if you wish to insert a new row just after another one in the table you need to take account of this in your sorting.
Take a look at this discussion which considers this: http://datatables.net/forums/comments.php?DiscussionID=227
Allan
I have a table without sorting(bSort: false)
Now, I want to add/delete/move rows according to row index of row selection.
How can I do it?
yoavs-t
Okay - without sorting then the order is entirely defined by the 'aiDisplayMaster' (pre filtering) and 'aiDisplay' (post filtering) arrays in DataTables' settings object (typically called oSettings - can be retrieved by fnSettings()). These variables are arrays of indexes which point to the data in the aoData array, and define the order that this data should be output.
What you could do is move the contents of these arrays around as you require (which is exactly how sorting works in DataTables), and then draw the table (fnDraw()).
Hope this helps!
Allan
I know this thread is old but I have code something to add a row in the middle of the table based on this thread. After executing the code I am showing below aiDisplay, aiDisplayMaster and aoData have the correct data on them, the problem is that nothing changes when calling fnDraw. Any thoughts?
[code]
/**
* Inserts the newly created quote after the affected row.
* @param {Object} iForm form used to create the quote
* @param {Object} insertedId inserted quote's id
*/
function insertNewQuoteInTable(iForm, insertedId){
var oDisplay = oTable.dataTableSettings[0].aiDisplay;
var oDisplayMaster = oTable.dataTableSettings[0].aiDisplayMaster;
var oData = oTable.dataTableSettings[0].aoData;
var affectedRowNbr = -1;
var COLUMN_WITH_ROW_ID = 4;
var ind = 0;
//look for affected row number
while (affectedRowNbr==-1 && ind','>I'),
iForm.price, ' ', iForm.quantity, ' ', ' ', ' ', ' ', aData[12], iForm.sequence];
var newRow = {
_aData : displayData,
_iId: oData[affectedRowNbr]._iId + 1,
_anHidden: oData[affectedRowNbr]._anHidden,
_sRowStripe: oData[affectedRowNbr]._sRowStripe,
nTr: oData[affectedRowNbr].nTr
};
//insert the new element
oDisplay.splice(ind, 0, ind);
oDisplayMaster.splice(ind, 0, ind);
oData.splice(ind, 0, newRow);
//update references
var i = 0;
for (i = ind+1; i
This plugin is so great, its like I dont have to compromise on anything!! I have the same doubt as above tho, I have disabled sorting and I want to add rows in the middle of the table. Is this possible? Since this post is really old, I want to confirm, that a solution has not already been found so I dont reinvent the wheel.. ! cheers