I would like to apply a default filter after the grid is loaded. What is the syntax for applying a filter in an HTML Helper (razor)? I pass the model to the grid constructor as in below -
@(Html.Infragistics().Grid(Model.Groups.AsQueryable()) .ID("grid1") .Columns(column => { column.For(c => c.Status).HeaderText("Status"); }) .Features(features => { features.Filtering().ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Status").AllowFiltering(true).FilterCondition("Starts With"); }); .DataBind() .Render() )
Hello Chris,
I am glad to hear that this worked for you. Feel free to let me know if any additional questions about our tool set arise.
Excellent information. Thanks!
You might be also interested that in our latest service release using default filtering expressions is also available. The example bellow illustrates how to use the new defaultExpression property (in bold):
@(Html.Infragistics().Grid(Model).ID("grid1").AutoGenerateColumns(false).EnableUTCDates(false).UpdateUrl(Url.Action("SaveData")).PrimaryKey("ProductID").Columns(col =>{ col.For(c => c.ProductID).HeaderText("ProductID").DataType("number"); col.For(c => c.Name).HeaderText("Name").DataType("string"); col.For(c => c.ReleaseDate).HeaderText("ReleaseDate").DataType("date");}).Features(feature =>{ feature.Filtering().ColumnSettings(cs=>cs.ColumnSetting().ColumnKey("ProductID").DefaultExpressions(new List<DefaultFilterExpression>{ new DefaultFilterExpre ssion () { Condition = "equals", Expression = "1"} }));}) .DataSourceUrl(Url.Action("GetData")).Render())
I have also attached the whole working sample.
If you need further information feel free to contact us.
Thank you for posting in our community!
In the code snippet you have provided it is used the right filtering syntax. However it is recommended to define the DataSourceUrl option and the type of filtering applied (local or remote). I have added an example code bellow (see the options in bold):
@(Html.Infragistics().Grid(Model).ID("grid1")
.Columns(column =>
{
column.For(x => x.ProductId).HeaderText("ID");
column.For(x => x.Name).HeaderText("Name");
column.For(x => x.Number).HeaderText("Quantity");
column.For(x => x.Distributor).HeaderText("Distributor");
column.For(x => x.Cost).HeaderText("Cost");
})
.Height("300px").Width("800px").PrimaryKey("ProductId")
.Features(feature =>
feature.Filtering().Type(OpType.Local).ColumnSettings(setting =>
setting.ColumnSetting().ColumnKey("ProductId").AllowFiltering(false).FilterCondition("equals");
setting.ColumnSetting().ColumnKey("Name").AllowFiltering(true).FilterCondition("endsWith");
setting.ColumnSetting().ColumnKey("Number").AllowFiltering(true).FilterCondition("equals");
setting.ColumnSetting().ColumnKey("Distributor").AllowFiltering(true).FilterCondition("startsWith");
setting.ColumnSetting().ColumnKey("Cost").AllowFiltering(true).FilterCondition("equals");
});
.DataSourceUrl(Url.Action("PagingGetData")).DataBind().Render())
Attached is a sample for your reference. Feel free to modify it and use it for your custom projects if needed. Please let me know if this helps. If you have any further questions don't hesitate to contact me.