comparing previous and current state
comparing previous and current state
Over two years ago, I had posted a question about this very topic. Unfortunately, it was never commented on. Thankfully, I finally figured out a manual solution.
"stateSaveParams": function (settings, data) {
settings.aoColumns.each(function(n,i) {
data.columns[i].className = n.nTh.className;
});
}
There was caveats to this:
(1) Verifying exact number of columns or more in new state
if (prevSettings && currSettings.aoColumns.length <= prevSettings.columns.length) {
return;
}
(2) Verifying new column was added at end as it throws off ColReorder
var valid = prevSettings.columns.every(function(n,i) {
return n.className === currSettings.aoColumns[i].nTh.className;
});
if (!valid) return;
For (2), I distinctly remember the order of the columns in settings.aoColumns, and therefore prevSettings.columns, matching the initial HTML markup. Anything pertaining to sorting, visibility, and ColReorder was handled via an attribute or object outside of the aoColumns array. However, this functionality seems to have changed the last time I updated DataTables (April/May 2017). Now, the column order physically changes in these arrays.
Is this intended functionality or a bug?
Answers
Hi @jr42.gordon ,
Even I feel your pain looking at those "bumps" in that first thread!
I just took a nose, take a look at the example here. There's some debug in the console that helps make sense of it.
The order of the aoColumns are the current position, but you can access the original ordering by looking at the ColReorder array in the
data
. You could marry those two together to see if any additional columns have been added then do your magic there.Hope that helps,
Cheers,
Colin
@colin While we are using that array to place the columns in their appropriate position, it contains no other information to go on. That is why I added "column.className" to the saved data, so that I would have something to compare against to ensure the table config is still valid and able to have ColReorder, visibility, etc re-applied to it.
I have advised that they look into storing "column._ColReorder_iOrigCol" in addition to "column.className", hoping that this value adheres to the original HTML markup position.