igniteui-angular icon indicating copy to clipboard operation
igniteui-angular copied to clipboard

igx-tree-grid issue in Filtering date column

Open prabakaran1311 opened this issue 7 years ago • 11 comments

Description

I am using angular 7 igx-tree-grid. In that if i am filtering date column is not working properly.

I am using Retemplating filter cell in that i didn't use date picker for date filter column(using normal input text filter) if i am manually entring only date or year it shows the result. But if am entring full date like 11-jun-2019 Grid is showing no data but when i console data is available.

Below is the sample code: https://stackblitz.com/edit/angular-3buayb

  • igniteui-angular version: 7.3.1
  • browser: All browser

Result

Retemplating filter cell date column not working if we manually entering date like 11-jun-2019.

Expected result

Retemplating filter cell date column should work even if we are entering manually in input text box filter

Attachments

fil

prabakaran1311 avatar Jun 13 '19 07:06 prabakaran1311

@prabakaran1311 You handle the case of a number column in the grid, but you're not handling the date column in your filtering conditions logic and your transform value logic. I've updated your stackblitz with the date column and the data transformation.

kdinev avatar Jun 13 '19 08:06 kdinev

@kdinev thanks for your reply. if i am changing datatype as string for date field its not working because if its a string means it should work whatever input right. Because i am using string datatype for date field. I have updated my stackblitz.

prabakaran1311 avatar Jun 13 '19 11:06 prabakaran1311

@prabakaran1311 You data source object contains date objects like this OrderDate: new Date("2003-03-17"). If you try to applying a contains filtering condition from the IgxStringFilteringOperand and pass it a date, it wouldn't actually manage to match it. If you want to treat the date as a string, then just fill the OrderDate properties with formatted string representations of the date.

kdinev avatar Jun 13 '19 12:06 kdinev

@kdinev already i have formatted date into string representation using formatter. but still its not working like string filter. Below is the formatter for date to string.

 DateFormatter(val: any) {
    if (val) {
        var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
        var date = new Date(val);
        var dat = date.getDate();
        var month = monthNames[date.getMonth()];
        var year = date.getFullYear();
        if (dat < 10) {
            return "0" + date.getDate() + "-" + monthNames[date.getMonth()] + "-" + date.getFullYear();
        }
        else {
            return date.getDate() + "-" + monthNames[date.getMonth()] + "-" + date.getFullYear();
        }
    }
    else {
        return "";
    }
}

prabakaran1311 avatar Jun 17 '19 09:06 prabakaran1311

@prabakaran1311 The default string contains condition doesn't have access to the column formatters and does not call them. The value that the filter is compared to is the underlying date object. You can include a custom filtering condition, which calls your formatter on the value and then calls the contains logic of the string filtering operand.

https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid/filtering.html#custom-filtering-operands

You can create something like StringDateFilteringOperand that extends the IgxStringFilteringOperand, and has a custom filter like dateStringContains that formats the value and calls the base contains filtering logic with it.

kdinev avatar Jun 17 '19 11:06 kdinev

@kdinev i have created custom filtering like above but its not working. here is the created sample https://stackblitz.com/edit/angular-njeivs can you let me know what is the issue in this sample.

prabakaran1311 avatar Jun 17 '19 12:06 prabakaran1311

I've updated your original stackblitz. I use your DateFormatter method inside the custom filter.

kdinev avatar Jun 17 '19 14:06 kdinev

@kdinev thanks now its working fine... :)

prabakaran1311 avatar Jun 18 '19 07:06 prabakaran1311

@prabakaran1311 Should I close the issue?

kdinev avatar Jun 18 '19 09:06 kdinev

@kdinev sure you can close this one. Thanks for your help

prabakaran1311 avatar Jun 18 '19 10:06 prabakaran1311

You're welcome!

kdinev avatar Jun 18 '19 10:06 kdinev