How to initialize MVC Grid filter value?

Answered (Verified) This post has 2 verified answers | 7 Replies | 5 Followers Thread's RSS feed.

Dean Wiles
Points 90
Replied On: Mon, Jan 4 2016 5:29 PM Reply

Can someone point me in the right direction? Using MVC, I have a web page that displays a grid with filters. I can manually filter records, however I would like to have one column (named "Active") to be filtered when the page loads as if the user had selected the filter Active = True. The page downloads all records (regardless of Active status) so that the user could chose to clear the filter and see all records without another roundtrip.

I looked through the online docs and samples but could not find where the specific MVC syntax for this is documented.

Below is what I have so far, but the filter initialization doesn't work and it displays all records.

Thanks in advance for your help.

@using Infragistics.Web.Mvc;

@model IQueryable<STRIPE_ASP461.EmployeeSummaryInfo>

@section Scripts {

<script type="text/javascript" src="@Url.Content("~/Scripts/Infragistics/js/infragistics.loader.js")"></script>

@(Html.Infragistics()

.Loader()

.ScriptPath(Url.Content("~/Scripts/Infragistics/js"))

.CssPath(Url.Content("~/Content/Infragistics/css"))

.Theme("infragistics")

.Render())

@(Html.Infragistics()

.Grid(Model)

.ID("igGrid")

.Width("600px")

.Height("800px")

.Caption("Employees")

.AutofitLastColumn(false)

.AutoGenerateColumns(false)

.Columns(column =>

{

column.For(x => x.LastName).HeaderText("Last Name").Width("150px");

column.For(x => x.FirstName).HeaderText("First Name").Width("150px");

column.For(x => x.EmployeeID).HeaderText("ID").Width("80px");

column.For(x => x.Active).HeaderText("Active").Width("50px");

})

.Features(f =>

{

f.ColumnMoving()

.Mode(MovingMode.Immediate);

f.Filtering()

.Type(OpType.Local)

.Mode(FilterMode.Simple)

.ColumnSettings(settings => {

settings.ColumnSetting() // Initially just show the Active records

.ColumnKey("Active")

.FilterCondition("true");

});

f.Hiding();

f.Paging()

.PageSize(20);

f.Resizing();

f.Responsive();

f.Selection()

.Mode(SelectionMode.Row);

f.Sorting()

.Mode(SortingMode.Multiple);

})

.RenderCheckboxes(true)

.DataBind()

.Render())

}

  • Post Points: 35

Verified Answer

Dean Wiles
Points 90
Answered (Verified) Replied On: Mon, Jan 4 2016 7:56 PM Reply
Verified by Dean Wiles

I still couldn't find the correct Razor syntax, but this worked to add the following JavaScript right after the Razor call:

.Render())...

<script type="text/javascript">

$.ig.loader(function () {

// Initially just show the Active records

$("#igGrid").igGridFiltering("filter", ([{ fieldName: "Active", expr: "True", cond: "true" }, ]));

});

</script>

}

  • Post Points: 20
[Infragistics]Tsanna
Points 15,050
Infragistics Employee
Answered (Verified) Replied On: Thu, Jan 7 2016 8:47 AM Reply
Verified by Dean Wiles

Hello Dean,

In order to set initial filtering expressions, so that they're applied with the grid initialization, you should use defaultExpressions columnSetting. For instance:

@{

var list = new List<DefaultFilterExpression>();

list.Add(new DefaultFilterExpression(){ Expression="false", Condition="false"});

}

...

.Features(f =>

{

f.Filtering().Mode(FilterMode.Simple).Type(OpType.Local).ColumnSettings(settings =>

{

settings.ColumnSetting().ColumnKey("Active").DefaultExpressions(list);

});

})

If you need further assistance, please let me know.

Regards,

Tsanna

Associate Software Developer

  • Post Points: 20

All Replies

Dean Wiles
Points 90
Answered (Verified) Replied On: Mon, Jan 4 2016 7:56 PM Reply
Verified by Dean Wiles

I still couldn't find the correct Razor syntax, but this worked to add the following JavaScript right after the Razor call:

.Render())...

<script type="text/javascript">

$.ig.loader(function () {

// Initially just show the Active records

$("#igGrid").igGridFiltering("filter", ([{ fieldName: "Active", expr: "True", cond: "true" }, ]));

});

</script>

}

  • Post Points: 20
[Infragistics]Tsanna
Points 15,050
Infragistics Employee
Answered (Verified) Replied On: Thu, Jan 7 2016 8:47 AM Reply
Verified by Dean Wiles

Hello Dean,

In order to set initial filtering expressions, so that they're applied with the grid initialization, you should use defaultExpressions columnSetting. For instance:

@{

var list = new List<DefaultFilterExpression>();

list.Add(new DefaultFilterExpression(){ Expression="false", Condition="false"});

}

...

.Features(f =>

{

f.Filtering().Mode(FilterMode.Simple).Type(OpType.Local).ColumnSettings(settings =>

{

settings.ColumnSetting().ColumnKey("Active").DefaultExpressions(list);

});

})

If you need further assistance, please let me know.

Regards,

Tsanna

Associate Software Developer

  • Post Points: 20
Dean Wiles
Points 90
Replied On: Thu, Jan 7 2016 1:14 PM Reply

Hi Tsanna,

Thank you for the code example! That helps to keep all the grid & filter initialization together.

Dean

  • Post Points: 35
[Infragistics]Tsanna
Points 15,050
Infragistics Employee
Replied On: Fri, Jan 8 2016 4:59 AM Reply

Hi Dean,

You're welcome. If you need further assistance, please let me know.

Regards,

Tsanna

Associate Software Developer

  • Post Points: 5
Rajesh
Points 15
Replied On: Wed, Jul 26 2017 1:23 AM Reply

GOod one thanks for this kind of information google mail for more detials

  • Post Points: 5
rajesh
Points 5
Replied On: Wed, Aug 9 2017 6:49 AM Reply

Its really good suggestions to have question and answer forum here to read more thanks for your suggestions for give us about gmail signin Login email account get your free account.

  • Post Points: 5
Page 1 of 1 (8 items) | RSS