Keith
Keith

Reputation: 4137

Get data from Kendo Grid

I'm trying to grab data from the main field in the Kendo grid and using it for the filter process. So when a user uses the filter, you click inside the input and the values show up for the user to select from whatever values are there. So far I have:

<div id="grid"></div>

$(document).ready(function () {
datasource = new kendo.data.DataSource({
     type: "json",
     data: @Html.Raw(JsonConvert.SerializeObject(Model.Programs)),
     batch: true,
     schema: {
          model: {
              fields: {
                   main: { type: "string" },
                   sub: { type: "string" }
              }
          }
     }
});

$("#grid").kendoGrid({
   dataSource: dataSource,
   pageable: true,
   columns: [
      { field: "main", filterable: { ui:main }, title: "Main" }
      { field: "sub", filterable: { ui:sub }, title: "Sub" }
   ],
        groupable: true,
        sortable: true,
        filterable: {
            extra: false,
            operators: {
                string: {
                    startswith: "Starts with",
                    eq: "Is equal to",
                    neq: "Is not equal to"
                }
            }
        }
});
function main(element) {
    element.kendoDropDownList({
        dataSource: main,
        optionLabel: "--Select Value--"
    });
}
});

Upvotes: 0

Views: 1331

Answers (1)

Maurosys
Maurosys

Reputation: 96

If you want populate the DropDown in filter with same data from grid, try use the same datasource of grid and set DropDown dataField, ex.:

function main(element) {
    element.kendoDropDownList({
        dataSource: datasource,
        dataTextField: 'main',
        optionLabel: "--Select Value--"
    });
}

Upvotes: 1

Related Questions