84 lines
3.3 KiB
Plaintext
84 lines
3.3 KiB
Plaintext
|
|
"processing": true,
|
|
"stateSave": true,
|
|
"pageLength": [% settings.table_pagesize %],
|
|
"lengthMenu": [% table_showrecordsmenu %],
|
|
"dom": '<"top"l<"nd_datatables-pager"p>f>rt<"bottom"><"clear">',
|
|
"language": {
|
|
"search": '_INPUT_',
|
|
"searchPlaceholder": 'Filter results...',
|
|
"lengthMenu": "Show _MENU_ rows."
|
|
},
|
|
"rowCallback": function (row, data) {
|
|
// update in-cell content based on current sidebar settings
|
|
$('.nd_dynamic-dp').each( function() {
|
|
$(row).find('span.' + $(this).attr('id')).toggle( $(this).prop('checked') );
|
|
});
|
|
},
|
|
"stateSaveParams": function (settings, data) {
|
|
var pgtitle = update_page_title('[% tabname %]');
|
|
update_browser_history('[% tabname %]', pgtitle, '');
|
|
// TODO: would be nice to update CSV link too
|
|
|
|
var datatable = $('#[% tabname %]_pane').find('table').first().DataTable();
|
|
var sidebarform = $('#[% tabname %]_form');
|
|
// if no existing state, all columns default to visible.
|
|
// on table load, state is saved... we can find out whether there was
|
|
// loaded state, and if not, use this hook to set initial column
|
|
// visibility.
|
|
if (datatable.state.loaded() === null) {
|
|
sidebarform.find('input[type="checkbox"]').each( function() {
|
|
var id = $(this).attr('id');
|
|
var col = datatable.column( id + ':name' );
|
|
if (col.length === 1) {
|
|
col.visible( $(this).prop('checked') );
|
|
data.columns[col.index()].visible = $(this).prop('checked');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
// save sidebar settings
|
|
data["sidebarform"] = sidebarform.serializeArray();
|
|
}
|
|
|
|
// make sure filter is never saved
|
|
data.search.search = "";
|
|
// make sure paging position is not saved
|
|
data.start = 0;
|
|
},
|
|
"stateLoadParams": function (settings, data) {
|
|
// load all sidebar settings
|
|
var sidebarform = $('#[% tabname %]_form');
|
|
sidebarform.deserialize( data.sidebarform );
|
|
},
|
|
"initComplete": function (settings, json) {
|
|
// find the current tab's datatables object
|
|
// then update sidebar checkboxes to hook the datatables colvis
|
|
var table = $('#[% tabname %]_pane').find('table').first();
|
|
var colvis = new table.dataTable.ColVis( table );
|
|
var columns = colvis.s.dt.aoColumns;
|
|
|
|
if ( $.inArray( 'all', colvis.s.exclude ) === -1 ) {
|
|
for ( var i=0, iLen=columns.length ; i<iLen ; i++ ) {
|
|
if ( $.inArray( i, colvis.s.exclude ) === -1 ) {
|
|
var button = colvis.dom.buttons.shift();
|
|
|
|
$(button).find('label').addClass('checkbox');
|
|
$(button).find('input').attr('id', columns[i]["name"]);
|
|
$(button).find('input').attr('name', columns[i]["name"]);
|
|
|
|
var target = $('#' + columns[i]["name"]);
|
|
$(button).find('span').text( target.closest('label').text() );
|
|
$(button).find('input').first().prop('checked', target.prop('checked'));
|
|
|
|
// need to re-activate tooltips on new content
|
|
$(button).click(function() {
|
|
$("[rel=tooltip]").tooltip({live: true});
|
|
});
|
|
|
|
target.closest('li').replaceWith( button );
|
|
}
|
|
}
|
|
}
|
|
}
|