Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | |
| 2 | |||
| 3 | var TableAdvanced = function () { |
||
| 4 | |||
| 5 | var initTable1 = function () { |
||
| 6 | var table = $('#sample_1'); |
||
| 7 | |||
| 8 | /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */ |
||
| 9 | |||
| 10 | /* Set tabletools buttons and button container */ |
||
| 11 | |||
| 12 | $.extend(true, $.fn.DataTable.TableTools.classes, { |
||
| 13 | "container": "btn-group tabletools-dropdown-on-portlet", |
||
| 14 | "buttons": { |
||
| 15 | "normal": "btn btn-sm default", |
||
| 16 | "disabled": "btn btn-sm default disabled" |
||
| 17 | }, |
||
| 18 | "collection": { |
||
| 19 | "container": "DTTT_dropdown dropdown-menu tabletools-dropdown-menu" |
||
| 20 | } |
||
| 21 | }); |
||
| 22 | |||
| 23 | var oTable = table.dataTable({ |
||
| 24 | |||
| 25 | // Internationalisation. For more info refer to http://datatables.net/manual/i18n |
||
| 26 | "language": { |
||
| 27 | "aria": { |
||
| 28 | "sortAscending": ": activate to sort column ascending", |
||
| 29 | "sortDescending": ": activate to sort column descending" |
||
| 30 | }, |
||
| 31 | "emptyTable": "No data available in table", |
||
| 32 | "info": "Showing _START_ to _END_ of _TOTAL_ entries", |
||
| 33 | "infoEmpty": "No entries found", |
||
| 34 | "infoFiltered": "(filtered1 from _MAX_ total entries)", |
||
| 35 | "lengthMenu": "Show _MENU_ entries", |
||
| 36 | "search": "Search:", |
||
| 37 | "zeroRecords": "No matching records found" |
||
| 38 | }, |
||
| 39 | |||
| 40 | "order": [ |
||
| 41 | [0, 'asc'] |
||
| 42 | ], |
||
| 43 | |||
| 44 | "lengthMenu": [ |
||
| 45 | [5, 15, 20, -1], |
||
| 46 | [5, 15, 20, "All"] // change per page values here |
||
| 47 | ], |
||
| 48 | // set the initial value |
||
| 49 | "pageLength": 10, |
||
| 50 | |||
| 51 | "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable |
||
| 52 | |||
| 53 | // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout |
||
| 54 | // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js). |
||
| 55 | // So when dropdowns used the scrollable div should be removed. |
||
| 56 | //"dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", |
||
| 57 | |||
| 58 | "tableTools": { |
||
| 59 | "sSwfPath": "../../../assets/global/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", |
||
| 60 | "aButtons": [{ |
||
| 61 | "sExtends": "pdf", |
||
| 62 | "sButtonText": "PDF" |
||
| 63 | }, { |
||
| 64 | "sExtends": "csv", |
||
| 65 | "sButtonText": "CSV" |
||
| 66 | }, { |
||
| 67 | "sExtends": "xls", |
||
| 68 | "sButtonText": "Excel" |
||
| 69 | }, { |
||
| 70 | "sExtends": "print", |
||
| 71 | "sButtonText": "Print", |
||
| 72 | "sInfo": 'Please press "CTR+P" to print or "ESC" to quit', |
||
| 73 | "sMessage": "Generated by DataTables" |
||
| 74 | }] |
||
| 75 | } |
||
| 76 | }); |
||
| 77 | |||
| 78 | var tableWrapper = $('#sample_1_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 79 | |||
| 80 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 81 | } |
||
| 82 | |||
| 83 | var initTable2 = function () { |
||
| 84 | var table = $('#sample_2'); |
||
| 85 | |||
| 86 | /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */ |
||
| 87 | |||
| 88 | /* Set tabletools buttons and button container */ |
||
| 89 | |||
| 90 | $.extend(true, $.fn.DataTable.TableTools.classes, { |
||
| 91 | "container": "btn-group tabletools-btn-group pull-right", |
||
| 92 | "buttons": { |
||
| 93 | "normal": "btn btn-sm default", |
||
| 94 | "disabled": "btn btn-sm default disabled" |
||
| 95 | } |
||
| 96 | }); |
||
| 97 | |||
| 98 | var oTable = table.dataTable({ |
||
| 99 | |||
| 100 | // Internationalisation. For more info refer to http://datatables.net/manual/i18n |
||
| 101 | "language": { |
||
| 102 | "aria": { |
||
| 103 | "sortAscending": ": activate to sort column ascending", |
||
| 104 | "sortDescending": ": activate to sort column descending" |
||
| 105 | }, |
||
| 106 | "emptyTable": "No data available in table", |
||
| 107 | "info": "Showing _START_ to _END_ of _TOTAL_ entries", |
||
| 108 | "infoEmpty": "No entries found", |
||
| 109 | "infoFiltered": "(filtered1 from _MAX_ total entries)", |
||
| 110 | "lengthMenu": "Show _MENU_ entries", |
||
| 111 | "search": "Search:", |
||
| 112 | "zeroRecords": "No matching records found" |
||
| 113 | }, |
||
| 114 | |||
| 115 | "order": [ |
||
| 116 | [0, 'asc'] |
||
| 117 | ], |
||
| 118 | "lengthMenu": [ |
||
| 119 | [5, 15, 20, -1], |
||
| 120 | [5, 15, 20, "All"] // change per page values here |
||
| 121 | ], |
||
| 122 | |||
| 123 | // set the initial value |
||
| 124 | "pageLength": 10, |
||
| 125 | "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable |
||
| 126 | |||
| 127 | // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout |
||
| 128 | // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js). |
||
| 129 | // So when dropdowns used the scrollable div should be removed. |
||
| 130 | //"dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", |
||
| 131 | |||
| 132 | "tableTools": { |
||
| 133 | "sSwfPath": "../../../assets/global/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", |
||
| 134 | "aButtons": [{ |
||
| 135 | "sExtends": "pdf", |
||
| 136 | "sButtonText": "PDF" |
||
| 137 | }, { |
||
| 138 | "sExtends": "csv", |
||
| 139 | "sButtonText": "CSV" |
||
| 140 | }, { |
||
| 141 | "sExtends": "xls", |
||
| 142 | "sButtonText": "Excel" |
||
| 143 | }, { |
||
| 144 | "sExtends": "print", |
||
| 145 | "sButtonText": "Print", |
||
| 146 | "sInfo": 'Please press "CTRL+P" to print or "ESC" to quit', |
||
| 147 | "sMessage": "Generated by DataTables" |
||
| 148 | }, { |
||
| 149 | "sExtends": "copy", |
||
| 150 | "sButtonText": "Copy" |
||
| 151 | }] |
||
| 152 | } |
||
| 153 | }); |
||
| 154 | |||
| 155 | var tableWrapper = $('#sample_2_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 156 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 157 | } |
||
| 158 | |||
| 159 | var initTable3 = function () { |
||
| 160 | var table = $('#sample_3'); |
||
| 161 | |||
| 162 | /* Formatting function for row details */ |
||
| 163 | function fnFormatDetails(oTable, nTr) { |
||
| 164 | var aData = oTable.fnGetData(nTr); |
||
| 165 | var sOut = '<table>'; |
||
| 166 | sOut += '<tr><td>Platform(s):</td><td>' + aData[2] + '</td></tr>'; |
||
| 167 | sOut += '<tr><td>Engine version:</td><td>' + aData[3] + '</td></tr>'; |
||
| 168 | sOut += '<tr><td>CSS grade:</td><td>' + aData[4] + '</td></tr>'; |
||
| 169 | sOut += '<tr><td>Others:</td><td>Could provide a link here</td></tr>'; |
||
| 170 | sOut += '</table>'; |
||
| 171 | |||
| 172 | return sOut; |
||
| 173 | } |
||
| 174 | |||
| 175 | /* |
||
| 176 | * Insert a 'details' column to the table |
||
| 177 | */ |
||
| 178 | var nCloneTh = document.createElement('th'); |
||
| 179 | nCloneTh.className = "table-checkbox"; |
||
| 180 | |||
| 181 | var nCloneTd = document.createElement('td'); |
||
| 182 | nCloneTd.innerHTML = '<span class="row-details row-details-close"></span>'; |
||
| 183 | |||
| 184 | table.find('thead tr').each(function () { |
||
| 185 | this.insertBefore(nCloneTh, this.childNodes[0]); |
||
| 186 | }); |
||
| 187 | |||
| 188 | table.find('tbody tr').each(function () { |
||
| 189 | this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]); |
||
| 190 | }); |
||
| 191 | |||
| 192 | /* |
||
| 193 | * Initialize DataTables, with no sorting on the 'details' column |
||
| 194 | */ |
||
| 195 | var oTable = table.dataTable({ |
||
| 196 | |||
| 197 | // Internationalisation. For more info refer to http://datatables.net/manual/i18n |
||
| 198 | "language": { |
||
| 199 | "aria": { |
||
| 200 | "sortAscending": ": activate to sort column ascending", |
||
| 201 | "sortDescending": ": activate to sort column descending" |
||
| 202 | }, |
||
| 203 | "emptyTable": "No data available in table", |
||
| 204 | "info": "Showing _START_ to _END_ of _TOTAL_ entries", |
||
| 205 | "infoEmpty": "No entries found", |
||
| 206 | "infoFiltered": "(filtered1 from _MAX_ total entries)", |
||
| 207 | "lengthMenu": "Show _MENU_ entries", |
||
| 208 | "search": "Search:", |
||
| 209 | "zeroRecords": "No matching records found" |
||
| 210 | }, |
||
| 211 | |||
| 212 | "columnDefs": [{ |
||
| 213 | "orderable": false, |
||
| 214 | "targets": [0] |
||
| 215 | }], |
||
| 216 | "order": [ |
||
| 217 | [1, 'asc'] |
||
| 218 | ], |
||
| 219 | "lengthMenu": [ |
||
| 220 | [5, 15, 20, -1], |
||
| 221 | [5, 15, 20, "All"] // change per page values here |
||
| 222 | ], |
||
| 223 | // set the initial value |
||
| 224 | "pageLength": 10, |
||
| 225 | }); |
||
| 226 | var tableWrapper = $('#sample_3_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 227 | |||
| 228 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 229 | |||
| 230 | /* Add event listener for opening and closing details |
||
| 231 | * Note that the indicator for showing which row is open is not controlled by DataTables, |
||
| 232 | * rather it is done here |
||
| 233 | */ |
||
| 234 | table.on('click', ' tbody td .row-details', function () { |
||
| 235 | var nTr = $(this).parents('tr')[0]; |
||
| 236 | if (oTable.fnIsOpen(nTr)) { |
||
| 237 | /* This row is already open - close it */ |
||
| 238 | $(this).addClass("row-details-close").removeClass("row-details-open"); |
||
| 239 | oTable.fnClose(nTr); |
||
| 240 | } else { |
||
| 241 | /* Open this row */ |
||
| 242 | $(this).addClass("row-details-open").removeClass("row-details-close"); |
||
| 243 | oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details'); |
||
| 244 | } |
||
| 245 | }); |
||
| 246 | } |
||
| 247 | |||
| 248 | var initTable4 = function () { |
||
| 249 | var table = $('#sample_4'); |
||
| 250 | |||
| 251 | /* Formatting function for row expanded details */ |
||
| 252 | function fnFormatDetails(oTable, nTr) { |
||
| 253 | var aData = oTable.fnGetData(nTr); |
||
| 254 | var sOut = '<table>'; |
||
| 255 | sOut += '<tr><td>Platform(s):</td><td>' + aData[2] + '</td></tr>'; |
||
| 256 | sOut += '<tr><td>Engine version:</td><td>' + aData[3] + '</td></tr>'; |
||
| 257 | sOut += '<tr><td>CSS grade:</td><td>' + aData[4] + '</td></tr>'; |
||
| 258 | sOut += '<tr><td>Others:</td><td>Could provide a link here</td></tr>'; |
||
| 259 | sOut += '</table>'; |
||
| 260 | |||
| 261 | return sOut; |
||
| 262 | } |
||
| 263 | |||
| 264 | /* |
||
| 265 | * Insert a 'details' column to the table |
||
| 266 | */ |
||
| 267 | var nCloneTh = document.createElement('th'); |
||
| 268 | nCloneTh.className = "table-checkbox"; |
||
| 269 | |||
| 270 | var nCloneTd = document.createElement('td'); |
||
| 271 | nCloneTd.innerHTML = '<span class="row-details row-details-close"></span>'; |
||
| 272 | |||
| 273 | table.find('thead tr').each(function () { |
||
| 274 | this.insertBefore(nCloneTh, this.childNodes[0]); |
||
| 275 | }); |
||
| 276 | |||
| 277 | table.find('tbody tr').each(function () { |
||
| 278 | this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]); |
||
| 279 | }); |
||
| 280 | |||
| 281 | var oTable = table.dataTable({ |
||
| 282 | |||
| 283 | // Internationalisation. For more info refer to http://datatables.net/manual/i18n |
||
| 284 | "language": { |
||
| 285 | "aria": { |
||
| 286 | "sortAscending": ": activate to sort column ascending", |
||
| 287 | "sortDescending": ": activate to sort column descending" |
||
| 288 | }, |
||
| 289 | "emptyTable": "No data available in table", |
||
| 290 | "info": "Showing _START_ to _END_ of _TOTAL_ entries", |
||
| 291 | "infoEmpty": "No entries found", |
||
| 292 | "infoFiltered": "(filtered1 from _MAX_ total entries)", |
||
| 293 | "lengthMenu": "Show _MENU_ entries", |
||
| 294 | "search": "Search:", |
||
| 295 | "zeroRecords": "No matching records found" |
||
| 296 | }, |
||
| 297 | |||
| 298 | "columnDefs": [{ |
||
| 299 | "orderable": false, |
||
| 300 | "targets": [0] |
||
| 301 | }], |
||
| 302 | "order": [ |
||
| 303 | [1, 'asc'] |
||
| 304 | ], |
||
| 305 | "lengthMenu": [ |
||
| 306 | [5, 15, 20, -1], |
||
| 307 | [5, 15, 20, "All"] // change per page values here |
||
| 308 | ], |
||
| 309 | // set the initial value |
||
| 310 | "pageLength": 10, |
||
| 311 | }); |
||
| 312 | |||
| 313 | var tableWrapper = $('#sample_4_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 314 | var tableColumnToggler = $('#sample_4_column_toggler'); |
||
| 315 | |||
| 316 | /* modify datatable control inputs */ |
||
| 317 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 318 | |||
| 319 | /* Add event listener for opening and closing details |
||
| 320 | * Note that the indicator for showing which row is open is not controlled by DataTables, |
||
| 321 | * rather it is done here |
||
| 322 | */ |
||
| 323 | table.on('click', ' tbody td .row-details', function () { |
||
| 324 | var nTr = $(this).parents('tr')[0]; |
||
| 325 | if (oTable.fnIsOpen(nTr)) { |
||
| 326 | /* This row is already open - close it */ |
||
| 327 | $(this).addClass("row-details-close").removeClass("row-details-open"); |
||
| 328 | oTable.fnClose(nTr); |
||
| 329 | } else { |
||
| 330 | /* Open this row */ |
||
| 331 | $(this).addClass("row-details-open").removeClass("row-details-close"); |
||
| 332 | oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details'); |
||
| 333 | } |
||
| 334 | }); |
||
| 335 | |||
| 336 | /* handle show/hide columns*/ |
||
| 337 | $('input[type="checkbox"]', tableColumnToggler).change(function () { |
||
| 338 | /* Get the DataTables object again - this is not a recreation, just a get of the object */ |
||
| 339 | var iCol = parseInt($(this).attr("data-column")); |
||
| 340 | var bVis = oTable.fnSettings().aoColumns[iCol].bVisible; |
||
| 341 | oTable.fnSetColumnVis(iCol, (bVis ? false : true)); |
||
| 342 | }); |
||
| 343 | } |
||
| 344 | |||
| 345 | var initTable5 = function () { |
||
| 346 | |||
| 347 | var table = $('#sample_5'); |
||
| 348 | |||
| 349 | /* Fixed header extension: http://datatables.net/extensions/scroller/ */ |
||
| 350 | |||
| 351 | var oTable = table.dataTable({ |
||
| 352 | "dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // datatable layout without horizobtal scroll |
||
| 353 | "scrollY": "300", |
||
| 354 | "deferRender": true, |
||
| 355 | "order": [ |
||
| 356 | [0, 'asc'] |
||
| 357 | ], |
||
| 358 | "lengthMenu": [ |
||
| 359 | [5, 15, 20, -1], |
||
| 360 | [5, 15, 20, "All"] // change per page values here |
||
| 361 | ], |
||
| 362 | "pageLength": 10 // set the initial value |
||
| 363 | }); |
||
| 364 | |||
| 365 | |||
| 366 | var tableWrapper = $('#sample_5_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 367 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 368 | } |
||
| 369 | |||
| 370 | var initTable6 = function () { |
||
| 371 | |||
| 372 | var table = $('#sample_6'); |
||
| 373 | |||
| 374 | /* Fixed header extension: http://datatables.net/extensions/keytable/ */ |
||
| 375 | |||
| 376 | var oTable = table.dataTable({ |
||
| 377 | |||
| 378 | // Internationalisation. For more info refer to http://datatables.net/manual/i18n |
||
| 379 | "language": { |
||
| 380 | "aria": { |
||
| 381 | "sortAscending": ": activate to sort column ascending", |
||
| 382 | "sortDescending": ": activate to sort column descending" |
||
| 383 | }, |
||
| 384 | "emptyTable": "No data available in table", |
||
| 385 | "info": "Showing _START_ to _END_ of _TOTAL_ entries", |
||
| 386 | "infoEmpty": "No entries found", |
||
| 387 | "infoFiltered": "(filtered1 from _MAX_ total entries)", |
||
| 388 | "lengthMenu": "Show _MENU_ entries", |
||
| 389 | "search": "Search:", |
||
| 390 | "zeroRecords": "No matching records found" |
||
| 391 | }, |
||
| 392 | |||
| 393 | "order": [ |
||
| 394 | [0, 'asc'] |
||
| 395 | ], |
||
| 396 | "lengthMenu": [ |
||
| 397 | [5, 15, 20, -1], |
||
| 398 | [5, 15, 20, "All"] // change per page values here |
||
| 399 | ], |
||
| 400 | "pageLength": 10, // set the initial value, |
||
| 401 | "columnDefs": [{ // set default column settings |
||
| 402 | 'orderable': false, |
||
| 403 | 'targets': [0] |
||
| 404 | }, { |
||
| 405 | "searchable": false, |
||
| 406 | "targets": [0] |
||
| 407 | }], |
||
| 408 | "order": [ |
||
| 409 | [1, "asc"] |
||
| 410 | ] |
||
| 411 | }); |
||
| 412 | |||
| 413 | var oTableColReorder = new $.fn.dataTable.ColReorder( oTable ); |
||
| 414 | |||
| 415 | var tableWrapper = $('#sample_6_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper |
||
| 416 | tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown |
||
| 417 | } |
||
| 418 | |||
| 419 | return { |
||
| 420 | |||
| 421 | //main function to initiate the module |
||
| 422 | init: function () { |
||
| 423 | |||
| 424 | if (!jQuery().dataTable) { |
||
| 425 | return; |
||
| 426 | } |
||
| 427 | |||
| 428 | console.log('me 1'); |
||
| 429 | |||
| 430 | initTable1(); |
||
| 431 | initTable2(); |
||
| 432 | initTable3(); |
||
| 433 | initTable4(); |
||
| 434 | initTable5(); |
||
| 435 | initTable6(); |
||
| 436 | |||
| 437 | console.log('me 2'); |
||
| 438 | } |
||
| 439 | |||
| 440 | }; |
||
| 441 | |||
| 442 | }(); |