I'm losing changes when a custom filter is applied. How do I keep changes when I apply a filter?

1 Answer 116 Views
Filter Grid
SK
Top achievements
Rank 2
Iron
Iron
SK asked on 04 Oct 2021, 02:15 PM | edited on 04 Oct 2021, 02:15 PM

I have detail grids for each row and when you make a change to the detail grid, it marks the parent grid as dirty. I then have a custom filter that looks for dirty rows and lets you toggle between showing modified rows or showing all rows. Works great except when I apply the filter, it tosses all the changes made to the detail grids. What can I do to keep those changes?

function toggleModifiedRows() {

    var grid = $("#grid").data("kendoGrid");
    var Filters = [];

    var buttonRows = document.getElementById('showModifiedRows');
    var buttonText = buttonRows.value;
    if (grid.dataSource.filter() != null) {
        Filters = grid.dataSource.filter().filters;
    }

    var FilterData = [];

    console.log(buttonText);
    if (buttonText == "Show Modified Rows") {
        buttonRows.value = "Show All Rows";
        var dirtyFilter = false;
        if (Filters.length > 0) {
            for (var i = 0; i < Filters.length; i++) {
                if (Filters[i].field == "dirty") { dirtyFilter = true; }
            }
        }
        if (!dirtyFilter) { FilterData = UpdateFilters(Filters, 'dirty', 'equals', true); }
    }
    else {
        buttonRows.value = "Show Modified Rows";

        if (Filters.length > 0) {
            for (var i = 0; i < Filters.length; i++) {
                if (Filters[i].field == "dirty") {
                    Filters.splice(i, 1);
                    break;
                }
            }
        }

        FilterData = Filters;
    }
    grid.dataSource.filter(FilterData);
};

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 07 Oct 2021, 07:40 AM

Hello SK,

I see you have submitted the same question as a support ticket. I will post here the response provided, for the benefit of the community:

When batch editing and InCell edit mode is enabled for the Grid all changes that are made by the users are initially available only client-side. These changes are persisted in the Grid DataSource when the SaveChanges button is clicked. If a filtering is applied to the Grid that would request the relevant records and refresh the Grid. As result the unsaved changes will be lost.

That said, in order to avoid losing the unsaved changes I can suggest adding a condition in the client-side logic that checks for any unsaved changes before applying filtering. In order to detect any pending changes in the Grid you can utilize the DataSource hasChanges() method. If the method returns true you can cancel the filtering and prompt the user that any pending changes will be lost. 

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Filter Grid
Asked by
SK
Top achievements
Rank 2
Iron
Iron
Answers by
Aleksandar
Telerik team
Share this question
or