0

Summary: I want to enter a text to the textbox, push the button, and the GridView should display the reduced content -- filtered by the value.

Details: Being a DevExpress APS.NET MVC 5 beginner, I have a simple demo application that uses the GridView. The first example uses the Gridview with filter row -- everything generated by the DevExpress (14.2) GridView wizard.

Initial state of the gridview

When entering some value to the column filter, the displayed content is reduced after a while:

Filtered content

I need to implement the alternative where I enter the value to the textbox, and the GridView content is updated only after pushing the Apply button:

I want filtering after pressing the Apply button

The view is defined as follows:

@{
    ViewBag.Title = "GridView filtering";
}

<h2>@ViewBag.Title</h2>

@Html.DevExpress().Label(settings =>
{
    settings.Name = "Label";
    settings.Text = "Filter for the Name column";
}).GetHtml()

@Html.DevExpress().TextBox(settings =>
{
    settings.Name = "TextBox";
}).GetHtml()

@Html.DevExpress().Button(settings =>
{
    settings.Name = "BtnApply";
    settings.Text = "Apply";
    settings.UseSubmitBehavior = true;
}).GetHtml()


@Html.Action("GridViewPartial")

I am lost on how to bind the button click to the functionality, how to get the textbox content, and how to pass it to the GridView and make it updated.

1 Answer 1

2

The Apply button should not perform submit in this scenario. Set its UseSubmitBehavior property to False. Handle the button's client-side Click event. To access it in mark-up, use ButtonSettings.ClientSideEvents:

@Html.DevExpress().Button(settings =>
{
    settings.Name = "BtnApply";
    settings.Text = "Apply";
    settings.UseSubmitBehavior = false;
    settings.ClientSideEvents.Click = "btnApplyClick";
}).GetHtml()

In the btnApplyClick JS function, use the TextBox'es clien-side GetText method to get the text typed in your TextBox. Then, use the Grid's client-side AutoFilterByColumn to apply your filter to the grid by the Name column:

<script type="text/javascript">
    function btnApplyClick(s, e) {
        var filter = TextBox.GetText();
        GridView.AutoFilterByColumn("Name", filter);
    }
</script>

Where "GridView" is the name of your GridView extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.