Sophonias
Sophonias

Reputation: 914

How to update and reload the datasource of a Kendo UI MVC grid from clientside upon search

I have a kendo UI grid which is similar to this

@(Html.Kendo().Grid<MyViewModel>()
        .Name("MyGrid")
        .Columns(columns =>
        {
            columns.Bound(a => a.column1);
            columns.Bound(a => a.column2;
        }
        .Pageable(page => page.PageSizes(true))
        .Scrollable(src => src.Height("auto"))
        .Sortable()
        .Filterable()
        .Reorderable(reorder => reorder.Columns(true))
        .ColumnMenu()
        .Events(e =>
            {
                e.DataBound("onDataBound");
            })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(10)
            .Read(read => read.Action("GetMyList_Read", "MyController"))  

        )
    )

The datasource on this grid is loaded from "GetMyList_Read" action upon page load. I have a filter which works by pushing filter parameters into the kendo builtin filters. And it works fine. I want to do search on the serverside code to improve performance, instead of loading the whole data to the client side and filter. Also one of the search parameters require searching a new DB table evertime search is performed so having a server side filer will help a lot.

Upvotes: 0

Views: 2659

Answers (1)

David Shorthose
David Shorthose

Reputation: 4497

You can just alter your read action to include

.Read(read => read.Action("GetMyList_Read", "MyController").Data("AddFilters"))

Then add some JavaScript to populate you filters something like this:

<script>
 Function AddFilters()
{
 Return { filter: "some value");
 }
</script>

Then just alter your read action to accept the additional parameter.

Eg public jsonresult GetMyList_Read([DataSourceRequest] DataSourceRequest request, string filter)

Hopefully this gives you enough to work with but if you need a more complete example let me know and I will post something a bit more complete

Upvotes: 2

Related Questions