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