Rui Martins
Rui Martins

Reputation: 2184

How to set a initial filter on a kendo grid with the value from a dropdownlist

I have this grid

@(Html.Kendo().Grid<TaskViewModel>()
      .Name("grid")
     ...
      .Columns(columns =>
      {
          columns.Bound(e => e.IsSelected)
              .Sortable(true)
              .Filterable(false)
              .Title(string.Empty);

          columns.Bound(e => e.WorkflowStep).Title("Task Status").Filterable(false);
          ...
      })
      .Filterable()
      ...
      .DataSource(dataSource => dataSource
          .Ajax()
          .Read(read => read.Action("AllTasks", "Cockpit").Data("includeFinishedTasks"))
          .ServerOperation(true)
          .Filter(f => f.Add(p => p.CurrentWorkflowStepId).IsEqualTo(2))
          )
      )

where I set an initial filter on the datasource.

.Filter(f => f.Add(p => p.CurrentWorkflowStepId).IsEqualTo(2))

Is there any way I can have something like this?

.Filter(f => f.Add(p => p.CurrentWorkflowStepId).IsEqualTo(DropDownListForCurrentWorkflowStepId.value()))

Tks in advance.

Upvotes: 2

Views: 4975

Answers (2)

user2244705
user2244705

Reputation: 381

You can achieve this by configuring the DataSource with a filter:

$("#mygrid").kendoGrid({
            filterable: true,
            dataSource: {
                type: "jsdo",
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,                    
                batch: true,
                filter: { field: "K_CP", operator: "eq", value: "59000" },
                  ...

Upvotes: 4

Przemysław Kleszcz
Przemysław Kleszcz

Reputation: 646

You can achieve such functionality by jQuery:

$(".k-grid").data("kendoGrid").dataSource.filter({ field: "CurrentWorkflowStepId", operator: "eq", value: "(dropdownlist value)" });

You can execute this code in dropdownlist onChange event or document.ready block - to initially filter your grid.

Upvotes: 3

Related Questions