jquery - Datatables shared parameters affected by sorting -


i have datatable can have n number of children datatable(s) can added/removed/recreated @ time. children share initialization parameters seems datatables affect original data structure.

when adding 2 children , sorting first one, second child inherit sorting when recreated. have created fiddle here: http://jsfiddle.net/wthy9/44/

var mydatatable; var index = 0; var parentparams = {     "order":[],     "columns":[         {"name":"col 1"},         {"name":"col 2"},         {"name":"col 3"},         {"name":"col 4"},     ], }; var childparams = {     "columns":[         {"name":"col 1"},         {"name":"col 2"},         {"name":"col 3"},     ],         "order":[], };  $(document).ready(function(){     mydatatable = $('#mytable').datatable(parentparams);      $('#createchild').click(function(e){         e.preventdefault();         if(typeof mydatatable.row(index).child() == "undefined"){             var $table = $($('#child_table').html());             $table.css('width','100%');             var newchildparams = $.extend({}, childparams);             var childtable = $table.datatable(newchildparams);             mydatatable.row(index).child(                 childtable.table().container()             );         }         mydatatable.row(index).child.show();         index++;     });  -    $('#recreatechild').click(function(e){         e.preventdefault();         var lastindex = index - 1;          var $table = $($('#child_table').html());         $table.css('width','100%');         var childtable = $table.datatable(childparams);         mydatatable.row(lastindex).child(             childtable.table().container()         );          mydatatable.row(lastindex).child.show();     });      $('#hidechild').click(function(e){         mydatatable.row(--index).child.hide();     }); }); 

steps:

  1. add 2 children
  2. sort first child on column
  3. recreate second child recreate button
  4. second child have inherited ordering (debugging shows default childparameters have ordering set instead of being empty array).

how can recreate children , keep sort order child being recreated?

edit: since there has been no answer nor comment have double posted question datatables forum.

var newchildparams = $.extend({}, childparams); shallow copy here, means newchildparams point childparams's address. if change variable in newchildparams, childparams update too.

the solution use deep copy var newobject = jquery.extend(true, {}, oldobject);. copy object memory address. can see the graph more details.

so edited deep copy #createchild , #recreatechild in code, can see demo @ jsfiddle.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -