Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text box search and filter the values in grid view using Kendo UI HTML5

Tags:

html

kendo-ui

how can I filter Grid filtering based on values we entered in text box.

I have one text box out side the grid and i want to search the whole grid based on the values i entered in textbox. step1:

<input id="btnSearch" type="button" value="search" />
<div id="grid">

step2:bing grid value from source

var gridResult = $("#grid").kendoGrid({
    dataSource: { data: database },
    scrollable: true,
    sortable: true,
    filterable: true,
    pageable: {
        input: true,
        numeric: false
    },
    columns: [
        {
            field: "id",
            title: "ID"
        },
        {
            field: "x",
            title: "x"
        },
        {
            field: "y"
        },
        {
            field: "z"
        },
        {
            field: "p"
        }
    ]
});

step3: script for text box .that is wat ever the values i have typed in text box if the values match in grid the result should show in grid.

$("#btnSearch").click(function () {
    $filter = new Array();
    $x = $("#txtSearch").val();
    if ($x) {
        $filter.push({ field:"x", operator:"contains", value:$x});
    }
    gridResult.datasource.filter($filter);
});
like image 326
user1877936 Avatar asked Dec 07 '12 05:12

user1877936


People also ask

How do I add a search box in kendo grid?

To add a search box into a kendo grid we need to add Toolbar and search properties while initializing the kendo grid. Fields is an array of each field defined for the kendo grid. From the above snippet, the search will be applied for the name and age field of the grid.

How do I set the default filter in kendo grid?

Solution. On the dataBound event of the grid, find the filter dropdown and select() the desired default filter option. On the filter event of the Grid, if the filter is cleared, select the desired default filter option.

What is Pageable in kendo grid?

kendo:grid-pageable-messagesThe text messages displayed in pager. Use this option to customize or localize the pager messages.


1 Answers

Where you have:

gridResult.datasource.filter($filter);

it should read:

gridResult.data("kendoGrid").dataSource.filter($filter);
  1. the s in dataSource is uppercase
  2. you have to add data("kendoGrid") either here or when you declare var gridResult.
like image 198
OnaBai Avatar answered Oct 02 '22 19:10

OnaBai