简体   繁体   中英

YADCF : range_date filter doesn't work with specific date format

I'm unable to make the range_date filter of yadcf to work. I'm using it with datatables.net. And I don't know if I am missing something or if it is a bug.

I'm using this date format for the original data passed to datatable : YYYY-MM-DDTHH:mm .

And I'm using this format to display the date in the datetime-picker : DD/MM/YYYY .

I have looked inside the yadcf plugin to see what it does, and it seems to get the row date from the original value passed to datatable (which in my case is in this format : 'YYYY-MM-DDTHH:mm') and read it with the format provided in moment_date_format . Then it compares this date with the ones in the range filter, those dates are in this format : 'DD/MM/YYYY', but yadcf still reads it with the format provided in moment_date_format .

I made a fiddle which shows the problem : http://jsfiddle.net/vatvat99/go5mxw0d/32/

var data = [
  {date: '2018-12-05T00:00'},
  {date: '2018-12-04T00:00'},
  {date: '2018-12-03T00:00'},
  {date: '2018-12-02T00:00'},
  {date: '2018-12-01T00:00'},
];

$(document).ready(function () {
  $('#example').dataTable({
    data: data,                    
    columnDefs: [{
      defaultContent: "-",
      targets: "_all"
    }],
    columns: [
      {
        name: 'date',
        data: 'date',
      }
    ],
  }).yadcf([
    { 
      column_number: 0, 
      filter_container_id: 'dateContainer',
      filter_type: 'range_date', 
      datepicker_type: 'bootstrap-datetimepicker',
      moment_date_format: 'YYYY-MM-DDTHH:mm',
      filter_plugin_options: {
        format: 'DD/MM/YYYY',
        showClear: true,
      }
    },
  ]);
});

Thanks for your help.

For now you can solve it by setting the same date format for moment_date_format and filter_plugin_options: { format: 'YYYY-MM-DDTHH:mm', , it happens because even though the filter_plugin_options.format is used to output date picker date selection later on in the filtering logic addRangeDateFilterCapability the moment_date_format is being used to parse it (you can call it a bug) , so for now use the same format and in addition you can open an issue with jsfiddle link attached on yadcf repo.

.yadcf([ { column_number: 0, filter_container_id: 'dateContainer', filter_type: 'range_date', datepicker_type: 'bootstrap-datetimepicker', moment_date_format: 'YYYY-MM-DDTHH:mm', filter_plugin_options: { format: 'YYYY-MM-DDTHH:mm', showClear: true, } },

See working jsfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM