Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initializeDataTableAjax( name, selectClause, fromClause, columns, editFunction, deleteFunction, additionalCommands )
- {
- var options = {
- deferRender: true,
- ajax: {
- 'url' : '/etc/ajax_list_provider.php',
- 'data':{
- 'selectClause' : selectClause,
- 'fromClause' : fromClause
- }
- },
- columns: columns,
- columnDefs: [
- { responsivePriority: 10, targets: 'inline-edit-indicator'}
- ],
- createdRow: _dtCreatedRow
- };
- _completeDatatablesInit( name, additionalCommands, options );
- $("#datatable tbody").on( 'click', 'a.edit', editFunction ).on( 'click', 'a.delete', deleteFunction );
- $("#datatable tbody tr td:first-child").attr( 'align', 'center' );
- }
- function _completeDatatablesInit( name, additionalCommands, options )
- {
- options.pageLength = 25;
- options.oLanguage = { "sSearch": "" };
- options.responsive = true;
- options.colReorder = true;
- options.stateSave = true;
- options.keys = true;
- options.order = [[ 1, 'asc' ]];
- options.lengthMenu = [[10, 25, 50, -1], [10, 25, 50, "All"]];
- var buttons = [
- {
- text: name ? 'Add New ' + name : 'Add New',
- className: 'table-command table-add',
- ctrlKey: true,
- key: 'a',
- action: function()
- {
- var form = document.forms.action_form;
- if( document.forms.action_form )
- {
- form.task.value = 'add';
- form.submit();
- }
- }
- },
- {
- extend: 'pdf',
- text: 'PDF',
- className: 'table-export',
- orientation: 'landscape',
- exportOptions: {
- columns: ':not(.noSort)',
- orthogonal: 'export'
- }
- },
- {
- extend: 'excel',
- text: 'XLSX',
- className: 'table-export',
- exportOptions: {
- columns: ':not(.noSort)',
- orthogonal: 'export'
- }
- },
- {
- extend: 'csv',
- className: 'table-export',
- exportOptions: {
- columns: ':not(.noSort)',
- orthogonal: 'export'
- }
- },
- {
- extend: 'print',
- className: 'table-export',
- exportOptions: {
- columns: ':not(.noSort)',
- orthogonal: 'export'
- }
- }
- ];
- if( additionalCommands )
- {
- buttons.push( additionalCommands );
- }
- options.buttons = buttons;
- options.initComplete = _dtInitComplete;
- var dataTable = $("#datatable");
- var table = dataTable.DataTable( options );
- dataTable.thfloat();
- return dataTable;
- }
- function _dtCreatedRow(row, data, dataIndex )
- {
- $( row ).children('td.inline-edit').on( 'click', function(){inlineEdit( this );} );
- }
- function _dtInitComplete(settings, json) {
- //Build the buttons
- //[...]
- table.on( 'key-focus', function ( e, datatable, cell ) {
- console.log('key-focus ' + cell.node() );//cell is undefined and therefore this fails
- inlineEdit( cell.node() );
- } );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement