Adding new row to filtered grid, make new row visible

6 posts, 0 answers
  1. Mudit
    Mudit avatar
    5 posts
    Member since:
    Mar 2020

    Posted 01 May 2020 Link to this post

    Hi All

    We have observed that if grid is filtered and user hits on add row button. The new row is added but is not visible. Which makes no good sense as user then keeps on hitting add row but doesn't see anything moving.

     

    Is there a way wherein we can make newly added row visible even if there is a filter applied.

     

    Thanks

    M.

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2189 posts

    Posted 05 May 2020 Link to this post

    Hi Mudit,

    This is achievable by modifying the filters in the Grid's dataSource "change" event handler. See this dojo example: https://dojo.telerik.com/EXeHoCAm/2

    The same logic is applicable to the MVC Grid helper.

    Attach the event handler in the DataSource Events configuration:

     .Events(events => events.Change("onDataSourceChange"))

    The handler:

    function onDataSourceChange(e) {
      if (e.action == "add") {
        var newItem = e.items[0];
        var filter = this.filter();
        if (filter) {
          var filters = filter.filters;
          var noValueFilter = { field: "ProductName", operator: "eq", value: "" };
    
          //add empty value to the filter conditions
    
          var newFilter = {
            logic: "or",
            filters: [noValueFilter, filter]
          };
    
          this.filter(newFilter);
        }
      }
    }

    Regards,
    Ivan Danchev
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. Mudit
    Mudit avatar
    5 posts
    Member since:
    Mar 2020

    Posted 05 May 2020 in reply to Ivan Danchev Link to this post

    Thanks for your reply Ivan

     

    This way partially works. I can see the new row added but the previous filter value is lost. Somehow data is still filtered but the filter menu has no value in it.

    Also, in your code you are getting newItem = e.Items[0] but not using is any where and similarly var filters is not used either. are we missing something here that will get us the required functionality ?

     

    Thanks

    M.

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2189 posts

    Posted 07 May 2020 Link to this post

    Hello ,

    You cannot retain the original filter and at the same time display a new record, since it does not match this filter. That is why the suggested approach removes the previous filter with one that has an empty value. As for the unused variables in the handler, they are leftovers from testing different approaches, so you can ignore them.

    Regards,
    Ivan Danchev
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  5. Mudit
    Mudit avatar
    5 posts
    Member since:
    Mar 2020

    Posted 07 May 2020 in reply to Ivan Danchev Link to this post

    but your code does retain the existing filter, just that it is nor visible in the filter dropdown.

    when we're joining a new filter for "" to existing filters I would expect the previously filter to be visible in dropdown

  6. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2189 posts

    Posted 11 May 2020 Link to this post

    Mudit,

    Try this modification to the logic in the "change":

    var newFilter = {
      logic: "or",
      filters: [filters[0], noValueFilter]
    };
    
    this.filter(newFilter);

    At my end this allows the filter to be persisted.

    Regards,
    Ivan Danchev
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top