Grid won't render data after date range filtering

0 Answers 21 Views
Grid
ziental
Top achievements
Rank 1
ziental asked on 05 Jul 2021, 09:33 PM

Hi everyone,

I've been banging my head with an issue with KendoUI grid (for JQuery) and I was hoping I could get some help.

I've implemented server side pagination and filtering in my project and I send all the filtering parameters to a stored procedure.

It works fine, both the filtering and the pagination. The problem is when the data is returned to the grid if I had made a date range filtering.

ONLY with date range filtering. If I search only by string columns, I have no issues. If I search by only a date (not a range), it works too.

My guess is that it doesn't like to have two filters with the same key.

Here's my filter function:


const DatagridFilter = (e) => {
    const grid = datagrid.getGrid();
    let CurrentFilters = grid.getOptions().dataSource.filter?.filters || [];

    let filters = []; 

    if (e.filter == null) {
        angular.forEach(CurrentFilters, function (value, key) {
            if (value.filters.some(item => item.field !== e.field)) {
                filters.push(value);
            }
        });
    } else {
        let NewFilter = { logic: e.filter.logic, filters: [] };
        e.filter.filters.map(f => {
            NewFilter.filters.push({
                field: f.field,
                operator: f.operator,
                value: f.value
            });
        });

        let exist = false;
        angular.forEach(CurrentFilters, function (value, key) {
            if (value.filters.some(item => item.field === e.field)) {
                exist = true;
                filters.push(NewFilter);
            }
            else {
                filters.push(value);
            }
        });
        if (!exist) {
            filters.push(NewFilter);
        }
    }

    datagrid.setGridFilters(kendo.stringify(filters));
    if (filters.length > 0) {
        GridBind(1);
    } else {
        datagrid.resetGridFilters();
    }
}

And here's my DataGrid definition:


$("#grid").kendoGrid({
        excel: {
            allPages: true
        },
        filterable: {
            extra: false,
            operators: {
                string: {
                    contains: "Contains",
                    startswith: "Starts with",
                    endswith: "Ends With",
                    doesnotcontain: "Doesn't contain",
                    doesnotstartwith: "Does not start",
                    eq: "Is equal to",
                    neq: "Is not equal to",
                    isempty: "Empty",
                    isnotempty: "Not empty",
                },
                number: {
                    eq: "Equal to",
                    neq: "Not equal to",
                    lt: "less than",
                    lte: "less than or equal to",
                    gt: "greater than",
                    gte: "greater than or equal to",
                    startswith: "Starts With",
                    contains: "Contains",
                    doesnotcontain: "Doesn't contain",
                    doesnotstartwith: "Does not start",
                    endswith: "Ends With",
                    isnull: "Is Null",
                    isnotnull: "Is Not Null",
                },
                date: {
                    gte: "From Date",
                    lte: "To Date"
                }
            }
        },
        filter: (e) => DatagridFilter(e),
        sort: (e) => DatagridSort(e),
        page: (e) => GridBind(e.page),
        sortable: true,
        autoBind: false,
        navigatable: true,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true,
        height: gridAutoHeight,
        toolbar: [{ template: kendo.template($("#templ_toolbar").html()) }],
        columns: datagridColumns
    });

Any ideas of what could be happening?

Thanks!

Martin
Telerik team
commented on 08 Jul 2021, 10:16 AM

Could you please elaborate what exactly is the issue when using a range filter? Is the returned data not filtered, or the server does not return data at all? Here we have a How-To article on using date range to filter the data. It is possible that whatever issue it is that you are experiencing is caused from the server logic. 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
ziental
Top achievements
Rank 1
Share this question
or