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

How to apply Grid Filter by ajax in razor view???

2 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nge
Top achievements
Rank 1
nge asked on 09 Dec 2013, 01:30 PM
I had been trying a lot to get adding filter in ajax (razor view)

Please someone helps me ... i am new and so much need your helps
Thank you so much...

i tried this one.

 $.ajax({
             contentType: "json",
             url: url,
             method: 'GET',
             success: function (d) {
                 // var dropdownpropertyvalue = $("#dropdownproperty").val(selectedIndex);
                 var grid = $("#GridProperty").data("kendoGrid");
                // grid.autoBind(false);
                 //grid.ajax();
                 grid.dataSource = new kendo.data.DataSource({ data: d });
                // grid.filter(filter.add({field: "EntityName", operator: "Contains", value: entityName}));
                 grid.dataSource.read();
                
                // grid.serverFiltering(true);
                 grid.dataSource.filter({ field: "EntityName", operator: "eq", value: dropdownpropertyvalue });
                 grid.refresh();
             }

         });
     }
(not working here    grid.dataSource.filter({ field: "EntityName", operator: "eq", value: dropdownpropertyvalue });)


In kendo, i can do like this for filter....

.DataSource(dataSource => dataSource
          .Ajax()
          .Batch(true)
          .ServerOperation(false)
          .Filter(filter => {
              filter.Add(p => p.EntityName).Contains(@ViewData["FirstEntity"].ToString());

          })
          .Model(x =>
          {
              x.Id(y => y.Id);
              x.Field(y => y.EntityName).Editable(false);
              x.Field(y => y.PropertyName).Editable(false);
              x.Field(y => y.Description).Editable(false);

          })
          .Read(read => read.Action("PropertiesRead", "Properties",new {toolId=1}))
          .Update(update => update.Action("OperationsUpdate", "Operations",new {toolId=1}))

and how to apply here tooId = (from js variable)?

2 Answers, 1 is accepted

Sort by
0
nge
Top achievements
Rank 1
answered on 11 Dec 2013, 05:53 AM
hmmmm no one replies ;(
0
Daniel
Telerik team
answered on 11 Dec 2013, 09:22 AM
Hello,

The code to set the dataSource filter with the filter method is correct. The operator should be changed to "contains" if the filter should be the same as the one used for the Filter server side method but besides that the code should work as expected. A problem will occur because of the way a new dataSource is assigned to the Gird:
grid.dataSource = new kendo.data.DataSource({ data: d });
You should use the setDataSource method if you need to change the dataSource so that the Grid binds to its change handler and unbinds the change handler for the old dataSource. Since you are changing the dataSource you might also use the filter configuration instead to set the filter in this scenario.


Regards,
Daniel
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
nge
Top achievements
Rank 1
Answers by
nge
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or