You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

688 lines
22 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. $(document).ready(function() {
  2. // Plugin data table
  3. $.fn.dataTable.Api.register('column().data().sum()', function() {
  4. return this.reduce(function(a, b) {
  5. var x = parseFloat(a) || 0;
  6. var y = parseFloat(b) || 0;
  7. return x + y;
  8. });
  9. });
  10. /* Init the table and fire off a call to get the hidden nodes. */
  11. var table = $('#dt-plugin-method').DataTable();
  12. $('<button class="btn btn-primary m-b-20">sum of age in all rows</button>')
  13. .prependTo('.dt-plugin-buttons')
  14. .on('click', function() {
  15. alert('Column sum is: ' + table.column(3).data().sum());
  16. });
  17. $('<button class="btn btn-primary m-r-10 m-b-20">sum of age of visible rows</button>')
  18. .prependTo('.dt-plugin-buttons')
  19. .on('click', function() {
  20. alert('Column sum is: ' + table.column(3, { page: 'current' }).data().sum());
  21. });
  22. $.fn.dataTable.ext.type.detect.unshift(
  23. function(d) {
  24. return d === 'Low' || d === 'Medium' || d === 'High' ?
  25. 'salary-grade' :
  26. null;
  27. }
  28. );
  29. $.fn.dataTable.ext.type.order['salary-grade-pre'] = function(d) {
  30. switch (d) {
  31. case 'Low':
  32. return 1;
  33. case 'Medium':
  34. return 2;
  35. case 'High':
  36. return 3;
  37. }
  38. return 0;
  39. };
  40. $('#dt-ordering').DataTable();
  41. /* Custom filtering function which will search data in column four between two values */
  42. $.fn.dataTable.ext.search.push(
  43. function(settings, data, dataIndex) {
  44. var min = parseInt($('#min').val(), 10);
  45. var max = parseInt($('#max').val(), 10);
  46. var age = parseFloat(data[3]) || 0; // use data for the age column
  47. if ((isNaN(min) && isNaN(max)) ||
  48. (isNaN(min) && age <= max) ||
  49. (min <= age && isNaN(max)) ||
  50. (min <= age && age <= max)) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. );
  56. var dtage = $('#dt-range').DataTable();
  57. // Event listener to the two range filtering inputs to redraw on input
  58. $('#min, #max').keyup(function() {
  59. dtage.draw();
  60. });
  61. /* Create an array with the values of all the input boxes in a column */
  62. $.fn.dataTable.ext.order['dom-text'] = function(settings, col) {
  63. return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
  64. return $('input', td).val();
  65. });
  66. }
  67. /* Create an array with the values of all the input boxes in a column, parsed as numbers */
  68. $.fn.dataTable.ext.order['dom-text-numeric'] = function(settings, col) {
  69. return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
  70. return $('input', td).val() * 1;
  71. });
  72. }
  73. /* Create an array with the values of all the select options in a column */
  74. $.fn.dataTable.ext.order['dom-select'] = function(settings, col) {
  75. return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
  76. return $('select', td).val();
  77. });
  78. }
  79. /* Create an array with the values of all the checkboxes in a column */
  80. $.fn.dataTable.ext.order['dom-checkbox'] = function(settings, col) {
  81. return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
  82. return $('input', td).prop('checked') ? '1' : '0';
  83. });
  84. }
  85. /* Initialise the table with the required column ordering data types */
  86. $(document).ready(function() {
  87. $('#dt-live-dom').DataTable({
  88. "columns": [
  89. null,
  90. { "orderDataType": "dom-text-numeric" },
  91. { "orderDataType": "dom-text", type: 'string' },
  92. { "orderDataType": "dom-select" }
  93. ]
  94. });
  95. });
  96. // Server side processing Data-table
  97. $('#dt-server-processing').DataTable({
  98. "processing": true,
  99. "serverSide": true,
  100. "ajax": "dt-json-data/scripts/server-processing.php",
  101. "columns": [
  102. { "data": "first_name" },
  103. { "data": "last_name" },
  104. { "data": "position" },
  105. { "data": "office" },
  106. { "data": "start_date" },
  107. { "data": "salary" }
  108. ]
  109. });
  110. $('#dt-http').DataTable({
  111. "processing": true,
  112. "serverSide": true,
  113. "ajax": {
  114. url: "dt-json-data/scripts/server-processing.php",
  115. data: function(d) {
  116. d.myKey = "myValue";
  117. // d.custom = $('#myInput').val();
  118. // etc
  119. }
  120. },
  121. "columns": [
  122. { "data": "first_name" },
  123. { "data": "last_name" },
  124. { "data": "position" },
  125. { "data": "office" },
  126. { "data": "start_date" },
  127. { "data": "salary" }
  128. ]
  129. });
  130. $('#dt-post').DataTable({
  131. "processing": true,
  132. "serverSide": true,
  133. "ajax": {
  134. url: "dt-json-data/scripts/post.php",
  135. type: "post"
  136. },
  137. "columns": [
  138. { "data": "first_name" },
  139. { "data": "last_name" },
  140. { "data": "position" },
  141. { "data": "office" },
  142. { "data": "start_date" },
  143. { "data": "salary" }
  144. ]
  145. });
  146. // Data-table ajax
  147. $('#dt-ajax-array').DataTable({
  148. "ajax": "dt-json-data/arrays.txt"
  149. });
  150. $('#dt-ajax-object').DataTable({
  151. "ajax": "dt-json-data/objects.txt",
  152. "columns": [
  153. { "data": "name" },
  154. { "data": "position" },
  155. { "data": "office" },
  156. { "data": "extn" },
  157. { "data": "start_date" },
  158. { "data": "salary" }
  159. ]
  160. });
  161. $('#dt-nested-object').DataTable({
  162. "processing": true,
  163. "ajax": "dt-json-data/objects_deep.txt",
  164. "columns": [
  165. { "data": "name" },
  166. { "data": "hr.position" },
  167. { "data": "contact.0" },
  168. { "data": "contact.1" },
  169. { "data": "hr.start_date" },
  170. { "data": "hr.salary" }
  171. ]
  172. });
  173. $('#dt-orthogonal').DataTable({
  174. ajax: "dt-json-data/orthogonal.txt",
  175. columns: [
  176. { data: "name" },
  177. { data: "position" },
  178. { data: "office" },
  179. { data: "extn" }, {
  180. data: {
  181. _: "start_date.display",
  182. sort: "start_date.timestamp"
  183. }
  184. },
  185. { data: "salary" }
  186. ]
  187. });
  188. var generatetable = $('#dt-generate-content').DataTable({
  189. "ajax": "dt-json-data/arrays.txt",
  190. "columnDefs": [{
  191. "targets": -1,
  192. "data": null,
  193. "defaultContent": "<button>Click!</button>"
  194. }]
  195. });
  196. $('#dt-generate-content tbody').on('click', 'button', function() {
  197. var data = generatetable.row($(this).parents('tr')).data();
  198. alert(data[0] + "'s salary is: " + data[5]);
  199. });
  200. $('#dt-render').DataTable({
  201. "ajax": "dt-json-data/arrays.txt",
  202. "deferRender": true
  203. });
  204. // Data source table js start
  205. $('#dom-table').DataTable();
  206. $('#ajax-table').DataTable({
  207. "ajax": 'dt-json-data/ajax-table.json'
  208. });
  209. // Jsource table start
  210. var dataSet = [
  211. ["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
  212. ["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
  213. ["Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"],
  214. ["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060"],
  215. ["Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700"],
  216. ["Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000"],
  217. ["Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500"],
  218. ["Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900"],
  219. ["Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500"],
  220. ["Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600"],
  221. ["Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560"],
  222. ["Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000"],
  223. ["Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600"],
  224. ["Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500"],
  225. ["Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750"],
  226. ["Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500"],
  227. ["Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000"],
  228. ["Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500"],
  229. ["Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000"],
  230. ["Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500"],
  231. ["Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000"],
  232. ["Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000"],
  233. ["Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450"],
  234. ["Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600"],
  235. ["Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000"],
  236. ["Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575"],
  237. ["Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650"],
  238. ["Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850"],
  239. ["Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000"],
  240. ["Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000"],
  241. ["Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400"],
  242. ["Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500"],
  243. ["Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"],
  244. ["Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"],
  245. ["Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"],
  246. ["Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"]
  247. ];
  248. $('#jsource-table').DataTable({
  249. data: dataSet,
  250. columns: [
  251. { title: "Name" },
  252. { title: "Position" },
  253. { title: "Office" },
  254. { title: "Extn." },
  255. { title: "Start date" },
  256. { title: "Salary" }
  257. ]
  258. });
  259. // Jsource table end
  260. // Server side script table start
  261. $('#server-table').DataTable({
  262. "processing": true,
  263. "serverSide": true,
  264. "ajax": "dt-json-data/server-table.php"
  265. });
  266. // Server side script table end
  267. // Data source table js end
  268. // Api table js start
  269. var t = $('#add-row-table').DataTable();
  270. var counter = 1;
  271. $('#addRow').on('click', function() {
  272. t.row.add([
  273. counter + '.1',
  274. counter + '.2',
  275. counter + '.3',
  276. counter + '.4',
  277. counter + '.5'
  278. ]).draw(false);
  279. counter++;
  280. });
  281. // Automatically add a first row of data
  282. $('#addRow').click();
  283. // Setup - add a text input to each footer cell
  284. $('#footer-search tfoot th').each(function() {
  285. var title = $(this).text();
  286. $(this).html('<input type="text" class="form-control" placeholder="Search ' + title + '" />');
  287. });
  288. // DataTable
  289. var table = $('#footer-search').DataTable();
  290. // Apply the search
  291. table.columns().every(function() {
  292. var that = this;
  293. $('input', this.footer()).on('keyup change', function() {
  294. if (that.search() !== this.value) {
  295. that
  296. .search(this.value)
  297. .draw();
  298. }
  299. });
  300. });
  301. $('#footer-select').DataTable({
  302. initComplete: function() {
  303. this.api().columns().every(function() {
  304. var column = this;
  305. var select = $('<select class="form-control form-control-sm"><option value=""></option></select>')
  306. .appendTo($(column.footer()).empty())
  307. .on('change', function() {
  308. var val = $.fn.dataTable.util.escapeRegex(
  309. $(this).val()
  310. );
  311. column
  312. .search(val ? '^' + val + '$' : '', true, false)
  313. .draw();
  314. });
  315. column.data().unique().sort().each(function(d, j) {
  316. select.append('<option value="' + d + '">' + d + '</option>')
  317. });
  318. });
  319. }
  320. });
  321. // Add Rows start
  322. var srow = $('#row-select').DataTable();
  323. $('#row-select tbody').on('click', 'tr', function() {
  324. $(this).toggleClass('selected');
  325. });
  326. $('#row-select-btn').on('click',function() {
  327. alert(srow.rows('.selected').data().length + ' row(s) selected');
  328. });
  329. // Add Rows end
  330. // Delete rows start
  331. var drow = $('#row-delete').DataTable();
  332. $('#row-delete tbody').on('click', 'tr', function() {
  333. if ($(this).hasClass('selected')) {
  334. $(this).removeClass('selected');
  335. } else {
  336. drow.$('tr.selected').removeClass('selected');
  337. $(this).addClass('selected');
  338. }
  339. });
  340. $('#row-delete-btn').on('click',function() {
  341. drow.row('.selected').remove().draw(!1);
  342. });
  343. // Delete rows end
  344. // /* Formatting function for row details - modify as you need */
  345. function format(d) {
  346. // `d` is the original data object for the row
  347. return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
  348. '<tr>' +
  349. '<td>Full name:</td>' +
  350. '<td>' + d.name + '</td>' +
  351. '</tr>' +
  352. '<tr>' +
  353. '<td>Extension number:</td>' +
  354. '<td>' + d.extn + '</td>' +
  355. '</tr>' +
  356. '<tr>' +
  357. '<td>Extra info:</td>' +
  358. '<td>And any further details here (images etc)...</td>' +
  359. '</tr>' +
  360. '</table>';
  361. }
  362. var ct = $('#child-table').DataTable({
  363. "ajax": "dt-json-data/ajax-child-rows.json",
  364. "columns": [{
  365. "className": 'details-control',
  366. "orderable": false,
  367. "data": null,
  368. "defaultContent": ''
  369. },
  370. { "data": "name" },
  371. { "data": "position" },
  372. { "data": "office" },
  373. { "data": "salary" }
  374. ],
  375. "order": [
  376. [1, 'asc']
  377. ]
  378. });
  379. // Add event listener for opening and closing details
  380. $('#child-table tbody').on('click', 'td.details-control', function() {
  381. var tr = $(this).closest('tr');
  382. var row = ct.row(tr);
  383. if (row.child.isShown()) {
  384. // This row is already open - close it
  385. row.child.hide();
  386. tr.removeClass('shown');
  387. } else {
  388. // Open this row
  389. row.child(format(row.data())).show();
  390. tr.addClass('shown');
  391. }
  392. });
  393. // Form input start
  394. var table = $('#form-input-table').DataTable();
  395. $('#form-input-btn').on('click',function() {
  396. var data = table.$('input, select').serialize();
  397. alert(
  398. "The following data would have been submitted to the server: \n\n" +
  399. data.substr(0, 120) + '...'
  400. );
  401. return false;
  402. });
  403. // Form input end
  404. // Show-hide table js start
  405. var sh = $('#show-hide-table').DataTable({
  406. "scrollY": "200px",
  407. "paging": false
  408. });
  409. $('a.toggle-vis').on('click', function(e) {
  410. e.preventDefault();
  411. // Get the column API object
  412. var column = sh.column($(this).attr('data-column'));
  413. // Toggle the visibility
  414. column.visible(!column.visible());
  415. });
  416. // Show-hide table js end
  417. // Search API start
  418. function filterGlobal() {
  419. $('#search-api').DataTable().search(
  420. $('#global_filter').val(),
  421. $('#global_regex').prop('checked'),
  422. $('#global_smart').prop('checked')
  423. ).draw();
  424. }
  425. function filterColumn(i) {
  426. $('#search-api').DataTable().column(i).search(
  427. $('#col' + i + '_filter').val(),
  428. $('#col' + i + '_regex').prop('checked'),
  429. $('#col' + i + '_smart').prop('checked')
  430. ).draw();
  431. }
  432. $('#search-api').DataTable();
  433. $('input.global_filter').on('keyup click', function() {
  434. filterGlobal();
  435. });
  436. $('input.column_filter').on('keyup click', function() {
  437. filterColumn($(this).parents('tr').attr('data-column'));
  438. });
  439. // Search API end
  440. // Api table js end
  441. // Styling js start
  442. $('#base-style').DataTable();
  443. $('#no-style').DataTable();
  444. $('#compact').DataTable();
  445. $('#table-style-hover').DataTable();
  446. // Styling js end
  447. $('#simpletable').DataTable();
  448. $('#order-table').DataTable({
  449. "order": [
  450. [3, "desc"]
  451. ]
  452. });
  453. $('#multi-colum-dt').DataTable({
  454. columnDefs: [{
  455. targets: [0],
  456. orderData: [0, 1]
  457. }, {
  458. targets: [1],
  459. orderData: [1, 0]
  460. }, {
  461. targets: [4],
  462. orderData: [4, 0]
  463. }]
  464. });
  465. $('#complex-dt').DataTable();
  466. $('#DOM-dt').DataTable({
  467. "dom": '<"top"i>rt<"bottom"flp><"clear">'
  468. });
  469. $('#alt-pg-dt').DataTable({
  470. "pagingType": "full_numbers"
  471. });
  472. $('#scr-vrt-dt').DataTable({
  473. "scrollY": "200px",
  474. "scrollCollapse": true,
  475. "paging": false
  476. });
  477. $('#scr-vtr-dynamic').DataTable({
  478. scrollY: '50vh',
  479. scrollCollapse: true,
  480. paging: false
  481. });
  482. $('#lang-dt').DataTable({
  483. "language": {
  484. "decimal": ",",
  485. "thousands": "."
  486. }
  487. });
  488. var table = $('#dom-jqry').DataTable();
  489. $('#dom-jqry tbody').on('click', 'tr', function() {
  490. var data = table.row(this).data();
  491. alert('You clicked on ' + data[0] + '\'s row');
  492. });
  493. $('#colum-rendr').DataTable({
  494. "columnDefs": [{
  495. // The `data` parameter refers to the data for the cell (defined by the
  496. // `data` option, which defaults to the column being worked with, in
  497. // this case `data: 0`.
  498. "render": function(data, type, row) {
  499. return data + ' (' + row[3] + ')';
  500. },
  501. "targets": 0
  502. },
  503. { "visible": false, "targets": [3] }
  504. ]
  505. });
  506. $('#multi-table').DataTable({
  507. "dom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>'
  508. });
  509. $('#complex-header').DataTable({
  510. "columnDefs": [{
  511. "visible": false,
  512. "targets": -1
  513. }]
  514. });
  515. $('#lang-file').DataTable({
  516. "language": {
  517. "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json"
  518. }
  519. });
  520. $.extend(true, $.fn.dataTable.defaults, {
  521. "searching": false,
  522. "ordering": false
  523. });
  524. $('#setting-default').DataTable();
  525. var table = $('#row-grouping').DataTable({
  526. "columnDefs": [
  527. { "visible": false, "targets": 2 }
  528. ],
  529. "order": [
  530. [2, 'asc']
  531. ],
  532. "displayLength": 25,
  533. "drawCallback": function(settings) {
  534. var api = this.api();
  535. var rows = api.rows({ page: 'current' }).nodes();
  536. var last = null;
  537. api.column(2, { page: 'current' }).data().each(function(group, i) {
  538. if (last !== group) {
  539. $(rows).eq(i).before(
  540. '<tr class="group"><td colspan="5">' + group + '</td></tr>'
  541. );
  542. last = group;
  543. }
  544. });
  545. }
  546. });
  547. // Order by the grouping
  548. $('#row-grouping tbody').on('click', 'tr.group', function() {
  549. var currentOrder = table.order()[0];
  550. if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
  551. table.order([2, 'desc']).draw();
  552. } else {
  553. table.order([2, 'asc']).draw();
  554. }
  555. });
  556. $('#footer-callback').DataTable({
  557. "footerCallback": function(row, data, start, end, display) {
  558. var api = this.api(),
  559. data;
  560. // Remove the formatting to get integer data for summation
  561. var intVal = function(i) {
  562. return typeof i === 'string' ?
  563. i.replace(/[\$,]/g, '') * 1 :
  564. typeof i === 'number' ?
  565. i : 0;
  566. };
  567. // Total over all pages
  568. total = api
  569. .column(4)
  570. .data()
  571. .reduce(function(a, b) {
  572. return intVal(a) + intVal(b);
  573. }, 0);
  574. // Total over this page
  575. pageTotal = api
  576. .column(4, { page: 'current' })
  577. .data()
  578. .reduce(function(a, b) {
  579. return intVal(a) + intVal(b);
  580. }, 0);
  581. // Update footer
  582. $(api.column(4).footer()).html(
  583. '$' + pageTotal + ' ( $' + total + ' total)'
  584. );
  585. }
  586. });
  587. $('#custm-tool-ele').DataTable({
  588. "dom": '<"toolbar">frtip'
  589. });
  590. $("div.toolbar").html('<b>Custom tool bar! Text/images etc.</b>');
  591. $('#row-callback').DataTable({
  592. "createdRow": function(row, data, index) {
  593. if (data[5].replace(/[\$,]/g, '') * 1 > 150000) {
  594. $('td', row).eq(5).addClass('highlight');
  595. }
  596. }
  597. });
  598. });