Mohsin Arif

Mohsin Arif

  • 307
  • 6k
  • 138.6k

initComplete not working ?

Mar 16 2020 7:31 AM
below is my code i load data from model. in MVC but filter is not showing in data table
  1. <script>  
  2.     $(document).ready(function () {         
  3.         var table = $('#tableReport').DataTable({  
  4.             initComplete: function () {  
  5.                 this.api().columns().every(function () {  
  6.                     var column = this;  
  7.                     var select = $('<select><option value=""></option></select>')  
  8.                         .appendTo($(column.footer()).empty())  
  9.                         .on('change', function () {  
  10.                             var val = $.fn.dataTable.util.escapeRegex(  
  11.                                 $(this).val()  
  12.                             );  
  13.   
  14.                             column  
  15.                                 .search(val ? '^' + val + '$' : ''truefalse)  
  16.                                 .draw();  
  17.                         });  
  18.   
  19.                     column.data().unique().sort().each(function (d, j) {  
  20.                         select.append('<option value="' + d + '">' + d + '</option>')  
  21.                     });  
  22.                 });  
  23.             },  
  24.             'columnDefs': [  
  25.                 {  
  26.                     'targets': 0,  
  27.                     'checkboxes': {  
  28.                         'selectRow'true  
  29.                     }  
  30.                 }  
  31.             ],  
  32.             'select': {  
  33.                 'style''multi'  
  34.             },  
  35.             'order': [[1, 'asc']]  
  36.         });  
  37.   
  38.         // Handle form submission event  
  39.         $('#frm-Report').on('submit', function (e) {  
  40.             var form = this;  
  41.             var arr = new Array();  
  42.   
  43.             var ReportID = $("#ReportId").val();  
  44.             var DateFrom = $('#startDate').val();  
  45.             var DateTo = $('#endDate').val();  
  46.             var start = new Date(DateFrom);  
  47.             var end = new Date(DateTo);  
  48.   
  49.             if (start <= end) {  
  50.                 var rows_selected = table.column(0).checkboxes.selected();  
  51.   
  52.                 if (rows_selected.length == 0) {  
  53.                     SendNotif("Ooopss!""No User is Selected"'error');  
  54.                     return false;  
  55.                 }  
  56.   
  57.                 // Iterate over all selected checkboxes  
  58.                 $.each(rows_selected, function (index, rowId) {  
  59.                     // Create a hidden element  
  60.                     arr.push(rowId);  
  61.                     $(form).append(  
  62.                         $('<input>')  
  63.                             .attr('type''hidden')  
  64.                             .attr('name''id[]')  
  65.   
  66.                             .val(rowId)  
  67.                     );  
  68.                 });  
  69.                 $(".se-pre-con").fadeIn("slow");  
  70.   
  71.   
  72.                 if (document.location.pathname.includes("Reports")) {  
  73.                     FormSubmitReport(arr, DateFrom, DateTo, ReportID);  
  74.                 }  
  75.                 else {  
  76.                     FormSubmitGenrate(arr, DateFrom, DateTo);  
  77.                 }  
  78.             }  
  79.             else {  
  80.                 SendNotif('Error!''Invalid Date Range''error');  
  81.             }  
  82.             // Prevent actual form submission  
  83.             e.preventDefault();  
  84.         });  
  85.   
  86.         function FormSubmitReport(arr, DateFrom, DateTo, ReportID) {  
  87.   
  88.             window.location = '/Report/Generate?data=' + arr + '?' + DateFrom + '?' + DateTo + '?' + ReportID;  
  89.   
  90.   
  91.         }  
  92.   
  93.         function FormSubmitGenrate(arr, DateFrom, DateTo) {  
  94.   
  95.             window.location = '/Adjustment/Generate?data=' + arr + '?' + DateFrom + '?' + DateTo;  
  96.   
  97.   
  98.         }  
  99.     });  
  100.   
  101.   
  102. </script>  

Answers (1)