jquery - Multiple Objects in an array -


im not jquery, need learn can realize projects im working on.

i use datatables select-extension multiselect table-rows. afterwards need work values of rows in php. of allready works charm, problem can use 1 table within form. means results of first table class "table_select" $_post-variable.

i tried change jquery-code iterate on objects class, made array , tried push array [array.length], still values in array[0].

what doing wrong?

    var table = [];  table[table.length] =  $('.table_select').datatable( {     'initcomplete': function(){     var api = this.api();      api         .rows()             .every(function(){            var data = this.data();            if(data[1] === '1'){               api.cells(this.index(), 0).checkboxes.select();            }         });     },     order: [[2, "asc"]],     paging:false,     info:false,     filter:false,     language: {         "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/german.json",     },     columns: [         null,         { "visible": false},         null     ],     'columndefs': [{         'targets': 0,         'checkboxes': {             'selectrow': true,             'selectall': false         }     }],     select: {         style: 'multi'     } });  flen = table.length; 

flen allways "1" in case, if have 4 tabes "table_select"-class.

thanks in advance help!

edit:

i changed code based on comments to:

table =  $('.table_select').datatable( {     'initcomplete': function(){     var api = this.api();      api         .rows()             .every(function(){            var data = this.data();            if(data[1] === '1'){               api.cells(this.index(), 0).checkboxes.select();            }         });     },     order: [[2, "asc"]],     paging:false,     info:false,     filter:false,     language: {         "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/german.json",     },     columns: [         null,         { "visible": false},         null     ],     'columndefs': [{         'targets': 0,         'checkboxes': {             'selectrow': true,             'selectall': false         }     }],     select: {         style: 'multi'     } });   alert(table.length); 

the alert in case allways "0".

edit2: example jsfiddle: jsfiddle.net/tu59s6ls

let me explain doing

var table = [];  // setting length 0 no value   table[table.length] = ... // here setting table[0] = ... 

this means setting entire value @ index 0. ever oblect coming jquery datatable set index 0 length of table 1

you need set entire value in table variable not @ index 0

table =  ... 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -