Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | var TableAjax = function () { |
| 2 | |||
| 3 | var initPickers = function () { |
||
| 4 | //init date pickers |
||
| 5 | $('.date-picker').datepicker({ |
||
| 6 | rtl: Metronic.isRTL(), |
||
| 7 | autoclose: true |
||
| 8 | }); |
||
| 9 | } |
||
| 10 | |||
| 11 | var handleRecords = function () { |
||
| 12 | |||
| 13 | var grid = new Datatable(); |
||
| 14 | |||
| 15 | grid.init({ |
||
| 16 | src: $("#datatable_ajax"), |
||
| 17 | onSuccess: function (grid) { |
||
| 18 | // execute some code after table records loaded |
||
| 19 | }, |
||
| 20 | onError: function (grid) { |
||
| 21 | // execute some code on network or other general error |
||
| 22 | }, |
||
| 23 | loadingMessage: 'Loading...', |
||
| 24 | dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options |
||
| 25 | |||
| 26 | // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout |
||
| 27 | // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/scripts/datatable.js). |
||
| 28 | // So when dropdowns used the scrollable div should be removed. |
||
| 29 | //"dom": "<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'<'table-group-actions pull-right'>>r>t<'row'<'col-md-8 col-sm-12'pli><'col-md-4 col-sm-12'>>", |
||
| 30 | |||
| 31 | "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie. |
||
| 32 | |||
| 33 | "lengthMenu": [ |
||
| 34 | [10, 20, 50, 100, 150, -1], |
||
| 35 | [10, 20, 50, 100, 150, "All"] // change per page values here |
||
| 36 | ], |
||
| 37 | "pageLength": 10, // default record count per page |
||
| 38 | "ajax": { |
||
| 39 | "url": "../demo/table_ajax.php", // ajax source |
||
| 40 | }, |
||
| 41 | "order": [ |
||
| 42 | [1, "asc"] |
||
| 43 | ] // set first column as a default sort by asc |
||
| 44 | } |
||
| 45 | }); |
||
| 46 | |||
| 47 | // handle group actionsubmit button click |
||
| 48 | grid.getTableWrapper().on('click', '.table-group-action-submit', function (e) { |
||
| 49 | e.preventDefault(); |
||
| 50 | var action = $(".table-group-action-input", grid.getTableWrapper()); |
||
| 51 | if (action.val() != "" && grid.getSelectedRowsCount() > 0) { |
||
| 52 | grid.setAjaxParam("customActionType", "group_action"); |
||
| 53 | grid.setAjaxParam("customActionName", action.val()); |
||
| 54 | grid.setAjaxParam("id", grid.getSelectedRows()); |
||
| 55 | grid.getDataTable().ajax.reload(); |
||
| 56 | grid.clearAjaxParams(); |
||
| 57 | } else if (action.val() == "") { |
||
| 58 | Metronic.alert({ |
||
| 59 | type: 'danger', |
||
| 60 | icon: 'warning', |
||
| 61 | message: 'Please select an action', |
||
| 62 | container: grid.getTableWrapper(), |
||
| 63 | place: 'prepend' |
||
| 64 | }); |
||
| 65 | } else if (grid.getSelectedRowsCount() === 0) { |
||
| 66 | Metronic.alert({ |
||
| 67 | type: 'danger', |
||
| 68 | icon: 'warning', |
||
| 69 | message: 'No record selected', |
||
| 70 | container: grid.getTableWrapper(), |
||
| 71 | place: 'prepend' |
||
| 72 | }); |
||
| 73 | } |
||
| 74 | }); |
||
| 75 | } |
||
| 76 | |||
| 77 | return { |
||
| 78 | |||
| 79 | //main function to initiate the module |
||
| 80 | init: function () { |
||
| 81 | |||
| 82 | initPickers(); |
||
| 83 | handleRecords(); |
||
| 84 | } |
||
| 85 | |||
| 86 | }; |
||
| 87 | |||
| 88 | }(); |