javascript - Datatables: How to disable filtering after init -


on page i'm running 1 datatables init script can initialize multiple tables @ once. let's want change options, e.g. disable filtering, on 1 of tables not all, best way approach this?

example : http://jsfiddle.net/hedvf/1165/

$(document).ready(function() {     $('.datatable').datatable({         "spaginationtype": "full_numbers"     });     $('#example2').datatable({         "bfilter": false     }); }); 

as can see have 2 tables in html loaded, initialize both of them @ same time selecting '.datatable' class, both have. disable filtering 2nd table, select table use id 'example2' 2nd table has. changing setting table doesn't work, popup indicates can't reinitialize table, should otherwise change initialize table's options?

you can access existing datatable object calling datatable no arguments:

var dt = $('#example2').datatable(); 

i don't know values capable of being modified after fact, may or may not work changing then:

dt.datatable.settings.bfiltered = false; 

if need @ initialization time can think of 2 options. first, filter out before calling datatable

$('.datatable').not('#example2').datatable(...); $('#example2').datatable(.. other options ...); 

alternatively, create mechanism setting options @ html level:

$('.datatable').each(function(k,ele) {     ele = $(ele);     var opts = {       spaginationtype: ele.data('pagination-type') || 'full_numbers',       bfilter: ele.data('bfilter') !== 'false'     }     // or set if exists     if (ele.data('bfilter')) {        opts.bfilter = ele.data('bfilter') === 'true';     }     ele.datatable(opts);  }); 

that may little overkill make html similar to:

<div class="datatable" data-bfilter="false" data-pagination-type="mypagination_option"></div> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -