Wednesday, January 23, 2019

yadcf

Yet Another DataTables Column Filter is a jQuery plugin.

 
 

Addendum 1/24/2019: Make a date column sort in descending order by default at a yadcf amid Razor and jQuery.

  • Map the your date to a string when casting from your POCO to your DTO with Automapper. If you cannot live without a real date at your view model you are going to have to have a second property for a stringified date.
  • Doctor up your stringified date like so:
    int counter = 1000000;
    myCollection.ForEach(x =>
    {
       x.MyDate = $"<span style='display:none;'>{counter.ToString()}
             </span> {x.MyDate}";
       counter++;
    });

    This allows for ascending sorting based on the hidden counter which fakes descending sorting for the date.
  • At the yadcf this column...
    { title: 'My Date', name: 'MyDate', data: 'myDate' },
    ...must become...
    { title: 'My Date', name: 'MyDate', data: 'myDate',
          render: (data, type, full) => `${data}` },

    The full here variable is kind of interesting. You may dot off of it and get at other properties for the object. I don't know what type does.

No comments:

Post a Comment