Changing dataset after changing column order
Changing dataset after changing column order
Hi,
I'm loving DataTables, but am having some difficulties regarding column reordering.
My scenario (shown here: http://jsfiddle.net/LvE9Q/11/) involves the creation of a DataTable with a fnRender handler for column 0 that either returns the column's data formatted as a date string or "Bad date" if the column's data is not a date. It then loads a data set in with column 0 being a date.
If I reorder the columns and click on the "Change Data" button, a different dataset - also with column 0 as a date - is loaded into the datatable like so:
[code]
oTable.fnClearTable();
oTable.fnAddData(dataSet);
oTable.fnDraw();
[/code]
At this point, because the column order has changed, the date fnRender handler is applied to column 1 instead of column 0, which leads to problems.
I recognise that I'm probably approaching this in the wrong way, but am struggling to think of a way of dealing with it better.
Can anyone suggest a way of loading a second dataset with the same schema into a DataTable so that it respects any column reordering that may have occurred since the first dataset was loaded in?
Thanks,
Adam
I'm loving DataTables, but am having some difficulties regarding column reordering.
My scenario (shown here: http://jsfiddle.net/LvE9Q/11/) involves the creation of a DataTable with a fnRender handler for column 0 that either returns the column's data formatted as a date string or "Bad date" if the column's data is not a date. It then loads a data set in with column 0 being a date.
If I reorder the columns and click on the "Change Data" button, a different dataset - also with column 0 as a date - is loaded into the datatable like so:
[code]
oTable.fnClearTable();
oTable.fnAddData(dataSet);
oTable.fnDraw();
[/code]
At this point, because the column order has changed, the date fnRender handler is applied to column 1 instead of column 0, which leads to problems.
I recognise that I'm probably approaching this in the wrong way, but am struggling to think of a way of dealing with it better.
Can anyone suggest a way of loading a second dataset with the same schema into a DataTable so that it respects any column reordering that may have occurred since the first dataset was loaded in?
Thanks,
Adam
This discussion has been closed.
Replies
Never mind. I noticed that I had stupidly made references to localhost in my JSFiddle rendering it useless for anyone else, so I updated it to use the latest nightlies of DataTables and Colreorder. And now the problem seems to have gone away!
Hey-ho.