Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $.extend( jQuery.fn.dataTableExt.oSort, {
- "date-uk-pre": function (a){
- return parseInt(moment(a, "DD/MM/YYYY").format("X"), 10);
- },
- "date-uk-asc": function (a, b) {
- return a - b;
- },
- "date-uk-desc": function (a, b) {
- return b - a;
- }
- });
- var edit_date_col_num = $('th:contains("Edit Date")').index();
- var entry_date_col_num = $('th:contains("Entry Date")').index();
- var table = $('.mainTable').DataTable( {
- pageLength: 20,
- colReorder: true,
- stateSave: true,
- stateDuration: 0,
- columnDefs: [
- { "type": "date-uk", targets: [ edit_date_col_num, entry_date_col_num ] }
- ],
- dom: 'Blfrtip',
- buttons: [
- 'copy', 'csv', 'excel', 'print',
- {
- extend: 'colvis',
- collectionLayout: 'fixed four-column',
- postfixButtons: [ 'colvisRestore' ]
- }
- ],
- language: {
- "emptyTable": "No results match your search",
- "zeroRecords": "No results found",
- //"processing": "<div align='center'><img src='/static/ajax-loader.gif'></div>",
- //"loadingRecords": "<div align='center'><img src='/static/ajax-loader.gif'></div>",
- },
- processing: true,
- serverSide: true,
- ajax: {
- "url": EE.BASE + "&C=addons_modules&M=show_module_cp&module=ion&method=ajax_results",
- "type": "POST"
- },
- columns: [
- <?php
- foreach($columns AS $key => $val)
- {
- $visible_cols = array('field_id_325', 'field_id_326', 'field_id_697', 'field_id_649', 'field_id_689', 'field_id_632', 'entry_date', 'edit_date', 'field_id_698', 'field_id_666');
- $visible = 'false';
- if(in_array($key,$visible_cols))
- {
- $visible = 'true';
- }
- echo '{';
- echo ' "visible": '.$visible.',';
- echo ' "data": "'.$key.'",';
- echo ' "class": "'.$key.'",';
- echo '},';
- }
- ?>
- ],
- <?php
- $id = $this->input->get('id');
- $action = $this->input->get('action');
- if(isset($action) && $action == 'load' && isset($id) && $id != '') :
- ?>
- "stateLoadCallback": function (settings) {
- var o;
- // Send an Ajax request to the server to get the data. Note that
- // this is a synchronous request since the data is expected back from the
- // function
- $.ajax( {
- "url": EE.BASE + "&C=addons_modules&M=show_module_cp&module=ion&method=state_save&action=load&id=<?php echo $id;?>",
- "async": false,
- "dataType": "json",
- "success": function (response) {
- response = JSON.parse(response);
- //console.log(response);
- o = response;
- }
- });
- return o;
- },
- <?php
- endif;
- ?>
- initComplete: function (settings) {
- this.api().columns().every( function () {
- var column = this;
- // Get the column number
- var col_num = column[0][0];
- // Do not do a select for date fields
- if(col_num ==edit_date_col_num || col_num ==entry_date_col_num)
- {
- var date_range = $('from <input name="edit_date_min" id="edit_date_min"/>')
- .appendTo( $(column.footer()).empty() )
- .on( 'keyup', function () {
- var val = $.fn.dataTable.util.escapeRegex(
- $(this).val()
- );
- column
- .search( val ? ''+val+'' : '', true, false )
- .draw();
- } );
- }
- else
- {
- var select = $('<select><option value=""></option></select>')
- .appendTo( $(column.footer()).empty() )
- .on( 'change', function () {
- var val = $.fn.dataTable.util.escapeRegex(
- $(this).val()
- );
- column
- .search( val ? '^'+val+'$' : '', true, false )
- .draw();
- } );
- column.data().unique().sort().each( function ( d, j ) {
- select.append( '<option value="'+d+'">'+d+'</option>' )
- } );
- }
- } );
- // Need to re-apply the selection to the select dropdowns
- var colsSearch = settings.aoPreSearchCols;
- var cols = settings.aoColumns;
- // Iterate through all cols to assign value to select/input fields
- for (var i = 0; i < cols.length; i++)
- {
- if(cols[i].bVisible == true)
- {
- var cell_class = cols[i].class;
- var value = colsSearch[i].sSearch;
- if(value!='')
- {
- value = value.replace("^", "").replace("$","").replace("\/", "/").replace("\/", "/");
- $("."+cell_class).find(":input").val(value);
- }
- }
- }
- },
- } );
- // Save a datatables state by clicking the save button
- $( ".save_state" ).click(function(e) {
- e.preventDefault();
- table.destroy();
- $('.mainTable').DataTable( {
- colReorder: true,
- stateSave: true,
- stateDuration: 0,
- "stateSaveCallback": function (settings, data) {
- var save_name = $('.save_name').val();
- // Send an Ajax request to the server with the state object
- $.ajax( {
- "url": EE.BASE + "&C=addons_modules&M=show_module_cp&module=ion&method=state_save&action=save&save_name="+save_name,
- "data": data,
- "dataType": "json",
- "type": "POST",
- "success": function (response)
- {
- //console.log(response);
- }
- } );
- },
- });
- //table.state.save();
- window.location.replace(EE.BASE + "&C=addons_modules&M=show_module_cp&module=ion&method=applications");
- });
- $( ".clear_state" ).click(function(e) {
- e.preventDefault();
- table.state.clear();
- window.location.replace(EE.BASE + "&C=addons_modules&M=show_module_cp&module=ion&method=applications");
- });
- $.fn.dataTableExt.afnFiltering.push(
- function( oSettings, aData, iDataIndex ) {
- var iFini = document.getElementById('edit_date_min').value;
- var iStartDateCol = edit_date_col_num;
- iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2);
- var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
- if ( iFini === "" )
- {
- return true;
- }
- else if ( iFini <= datofini)
- {
- return true;
- }
- return false;
- console.log("Search: "+iFini);
- console.log("Date: "+datofini);
- }
- );
- // Event listener to the two range filtering inputs to redraw on input
- $('#edit_date_min, #edit_date_max').keyup( function() {
- table.draw();
- } );
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement