datetime-table.js 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var minDate, maxDate;
  2. // Custom filtering function which will search data in column four between two values
  3. $.fn.dataTable.ext.search.push(
  4. function( settings, data, dataIndex ) {
  5. var min = minDate.val();
  6. var max = maxDate.val();
  7. var date = new Date( data[4] );
  8. if (
  9. ( min === null && max === null ) ||
  10. ( min === null && date <= max ) ||
  11. ( min <= date && max === null ) ||
  12. ( min <= date && date <= max )
  13. ) {
  14. return true;
  15. }
  16. return false;
  17. }
  18. );
  19. // Create date inputs
  20. minDate = new DateTime($('#min'), {
  21. format: 'MMMM Do YYYY'
  22. });
  23. maxDate = new DateTime($('#max'), {
  24. format: 'MMMM Do YYYY'
  25. });
  26. // DataTables initialisation
  27. var table = $('#datetime-table').DataTable();
  28. // Refilter the table
  29. $('#min, #max').on('change', function () {
  30. table.draw();
  31. });
  32. //______Select2
  33. $('.select2').select2({
  34. minimumResultsForSearch: Infinity
  35. });