jquery - Datatables change options individually -


i'm working datatables , ran problem.

i have multi tables in 1 page (as in system), of them have commom options, datasource, responsive, etc.. of tables have unique options, bsort, aocolumns , on...

so question is: can initialize of them commom options , change options separate?


right now, how i'm doing:

var tabclientefisico_01 = $('#cfisico').datatable({     responsive: true,     bprocessing: true,     bserverside: false,     aocolumns : [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" },         { "mdata": "tel" },         { "mdata": "cidade" }     ],     "ajax": {         "url": "data/c_fisico.json",     },     "datatype": "json" });  var tabclientefisico_02 = $('#cfisico2').datatable({     responsive: true,     bprocessing: true,     bserverside: false,     bsort: false,     aocolumns: [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" }     ],     "ajax": {         "url": "data/c_fisico.json",     },     "datatype": "json" }); 

and i'd do:

var maintab = $('.maintab').datatable({     responsive: true,     bprocessing: true,     bserverside: false,     "ajax": {         "url": "data/c_fisico.json",     },     "datatype": "json" }); var tabclientefisico_01 = $('#cfisico1').datatable({     aocolumns: [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" },         { "mdata": "tel" },         { "mdata": "cidade" }     ] }); var tabclientefisico_02 = $('#cfisico2').datatable({     bsort: false,     aocolumns: [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" }     ] }); 

and in html be:

<table id="cfisico1" class"maintab"> ... </table> <table id="cfisico2" class"maintab"> ... </table> 

is there way this?

you can extend option object passed parameter datatable method, e.g:

var options = {     responsive: true,     bprocessing: true,     bserverside: false };  var opt01 = $.extend({}, options, {     aocolumns: [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" },         { "mdata": "tel" },         { "mdata": "cidade" }     ] }); var opt02 = $.extend({}, options, {     bsort: false,     aocolumns: [         { "mdata": "id" },         { "mdata": "nm_cliente" },         { "mdata": "cpf" }     ] });  var tabclientefisico_01 = $('#cfisico1').datatable(opt01),     tabclientefisico_02 = $('#cfisico2').datatable(opt02); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -