ColReorder State Saving-"Cannot read property '_ColReorder_iOrigCol' of undefined"

ColReorder State Saving-"Cannot read property '_ColReorder_iOrigCol' of undefined"

gabo_27gabo_27 Posts: 4Questions: 1Answers: 0

Hi,

First, I would like to say thank you for this incredible tool.

Now the problem, I am having an issue integrating the version ColReorder 1.1.1 and DataTables 1.10.0. If the configuration is set to "bStateSave" : true, the fist time the table is displayed correctly, the state is saved and the render is correct, but the second time when the table is created from the stored configuration I started getting this issue.

Uncaught TypeError: Cannot read property '_ColReorder_iOrigCol' of undefined

I try to follow the example at http://datatables.net/release-datatables/extensions/ColReorder/examples/state_save.html, but seems it is having the same issue.

Debugging the code, I found the problem is the method _fnLoadState, it is transforming the aaSorting array and passing this array to the event aoStateLoaded and stateLoaded. The array was stored like this "aaSorting":[[0,"asc"]], but when it is passed to the ColReorder method "_fnStateSave" the array was transformed to this "aaSorting": [0,"asc"].

Throwing the exception at:

oState.aaSorting[i][0] = oSettings.aoColumns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol;

I fixed this problem in my local passing an array instead of the oData.aaSorting property to $.map in the method:

Before:
oSettings.aaSorting = $.map(oData.aaSorting, function ( col, i ) {

Fix:
oSettings.aaSorting = $.map([oData.aaSorting], function ( col, i ) {

Now it is working and all the functions looks good, here is my configuration.
$('#myTable').dataTable({
"destroy" : true,
"dom" : 'Rlfrtip',
"bFilter" : false,
"sScrollY" : 500,
"iDeferLoading": 0,
"scrollX" : "100%",
"columnDefs" : [
{"title" :"name",
"defaultContent" : "-",
"targets" : 0,
"data" : "name"
},
{"title" :"last name",
"defaultContent" : "-",
"targets" : 1,
"data" : "lastName"
}
],
"data" : [{"name": "user a", "lastName": "last name a"},{"name": "user b", "lastName": "last name b"}]],
"bStateSave" : true,
"oLanguage": {
"sEmptyTable": "No results found",
"sZeroRecords": "No records to display"
}
});

I am not sure if this is the correct fix or if there is something else that will be affected, I appreciate any feedback about it.

Thanks,

Gabo

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Hi Gabo,

    It does look like this is an error in ColReorder. There was a github issue opened for it yesterday and I'll take a look into it when I next get into the office.

    Allan

  • gabo_27gabo_27 Posts: 4Questions: 1Answers: 0

    Thank you Allan, I will wait for the fix.

    Gabo

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin
    Answer ✓

    This was an error in DataTables unfortunately. I've just committed a fix and it will be in the DataTables nightly soon.

    Allan

  • gabo_27gabo_27 Posts: 4Questions: 1Answers: 0

    Thank you Allan, I appreciate the time you took to solve this problem, I will apply the same change to my local code.

    Gabo

This discussion has been closed.