This is a migrated thread and some comments may be shown as answers.

Issues adding a row while the grid has a filter

1 Answer 7 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 17 Jul 2015, 06:43 PM

I have put the below code on my dataSource.  It is inserting the data into the dataSource like it should but the row does not show up on the grid unless I do something on the grid like changing the sort.  Do I need to re-sync the grid with the dataSource?  If so how do I do that?

        change: function (e) {
            if (e.action == "add") {
                var newItem = e.items[0];

                if (this.filter() != undefined) {
                    var filter = this.filter().filters;
                    var i = filter.length;
                    while (i--) {
                        filterValue = filter[i].value;
                        filterField = filter[i].field;
                        switch (filterField) {
                            case "product.textField":
                                newItem.product.textField = filterValue;
                                break;
                            case "product.valueField":
                                newItem.product.valueField = filterValue;
                                break;
                            default:
                                newItem[filterField] = filterValue;
                        }
                    }
                }
            }
        }
 thx!

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 21 Jul 2015, 02:59 PM
Hello Greg,

This is somewhat expected, because using the assignment operator does not trigger a change event. As a result, the Grid does not get notified about the newly added item unless another change is triggered. Manually triggering the change event of the dataItem should be sufficient. For example: 
change: function (e) {
  if (e.action == "add") {
    var newItem = e.items[0];
 
    if (this.filter() != undefined) {
      var filter = this.filter().filters;
      var i = filter.length;
      while (i--) {
        filterValue = filter[i].value;
        filterField = filter[i].field;
        switch (filterField) {
          case "product.textField":
            newItem.product.textField = filterValue;
            break;
          case "product.valueField":
            newItem.product.valueField = filterValue;
            break;
          default:
            newItem[filterField] = filterValue;
        }
        newItem.trigger("change");
      }
    }
  }
},


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or