Created
July 4, 2017 12:46
-
-
Save mzalazar/c8573e3a0ae1a1c174529a419d2b9124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Initialize datatables */ | |
datatable = $('#dt_users').dataTable({ | |
// Tabletools options: | |
// https://datatables.net/extensions/tabletools/button_options | |
fixedHeader: true, | |
processing: true, | |
serverSide: true, | |
stateSave: true, | |
ajax: { | |
url : '/api/users', | |
data : function(d) { | |
var client_id = $('#selectClient').val(); | |
if(client_id == 0) { | |
delete d.client_id; | |
} else { | |
d.client_id = client_id; | |
} | |
}, | |
dataSrc: function(json) { | |
json.data.forEach(function(row, i) { | |
row.DT_RowId = 'rowId_' + row.DT_RowId; | |
html = swig.render($('#actionColumn').html(), {locals: row}); | |
row.actions = html; | |
row.activeHTML = row.active == 1 ? 'Yes' : 'No'; | |
}); | |
return json.data; | |
} | |
}, | |
sDom: "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-6 hidden-xs'T>r>"+ | |
"t"+ | |
"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>", | |
oTableTools: { | |
aButtons: [ | |
"copy", | |
"csv", | |
"xls", | |
{ | |
sExtends: "pdf", | |
sTitle: "SmartAdmin_PDF", | |
sPdfMessage: "SmartAdmin PDF Export", | |
sPdfSize: "letter" | |
}, | |
{ | |
sExtends: "print", | |
sMessage: "Generated by SmartAdmin <i>(press Esc to close)</i>" | |
} | |
], | |
sSwfPath: "/js/plugins/datatables/swf/copy_csv_xls_pdf.swf" | |
}, | |
autoWidth : true, | |
preDrawCallback : function() { | |
}, | |
drawCallback : function(oSettings) { | |
}, | |
fnCreatedRow: function( nRow, aData, iDataIndex ) { | |
}, | |
fnRowCallback: function( nRow, aData ) { | |
var $nRow = $(nRow); // cache the row wrapped up in jQuery | |
if(aData.deleted_at) { | |
$nRow.addClass('warning'); // user is inactive | |
} else if(!!!+aData.active) { | |
$nRow.addClass('danger'); // user is deleted | |
} | |
return nRow; | |
}, | |
columns: [ | |
{ "data": "client.company" }, | |
{ "data": "username" }, | |
{ "data": "email" }, | |
{ "data": "firstname"}, | |
{ "data": "timezone.abbreviation" }, | |
{ "data": "language.name" }, | |
{ "data": "activeHTML"}, | |
{ "data": "actions"} | |
], | |
columnDefs: [ | |
{ "min-width": "110px", "targets": 3 }, | |
] | |
}); | |
/* END TABLETOOLS */ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment