This is a migrated thread and some comments may be shown as answers.

How to remove grid's filter programmatically

5 Answers 2132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wonderer
Top achievements
Rank 1
Wonderer asked on 13 Nov 2012, 02:25 PM
Hello,

I'm wondering if what I'm doing to remove the grid's filter is correct or if there's a right approach.

Here's the code

var filter = { };
grid.dataSource.filter(filter);

5 Answers, 1 is accepted

Sort by
0
Just
Top achievements
Rank 1
answered on 13 Nov 2012, 07:36 PM
You are doing it right.
I'd implemented the kendoAutoComplete to search for text within the grid and after emptying the search textbox I would do like so

myGrid.data("kendoGrid").dataSource.filter({});
0
Irene
Top achievements
Rank 1
answered on 13 Nov 2012, 10:12 PM
how about if I want to remove grid's group programatically?  Is it the same?
0
Wonderer
Top achievements
Rank 1
answered on 14 Nov 2012, 02:17 AM
@just

Thank you, I thought I'm not doing it the right way, so now I'm having issue with that :)

I have a search box that triggers to filter the grid. The problem is happening when the grid becomes empty because there are no results based on the keyword entered on the search box.

Supposedly, grid must returned its original records when the search box is empty but its not. When doing 
var filter = { };
grid.dataSource.filter(filter); 

The grid is still empty also when checking the grid on firebug. It just say grid.dataSource {...} without any on it. Do you know what causing the problem?
0
Just
Top achievements
Rank 1
answered on 15 Nov 2012, 02:46 PM
Try
grid.data("kendoGrid").dataSource.filter(filter); 

The sample code I posted before was for exactly that purpose.
So I had 
var myGrid = $("#myGrid").kendoGrid({
	//set up grid data source and other configurations here.
});

And then later for the search textbox

$("#myGridSearch").kendoAutoComplete({
        change: function () {
var value = this.value(); if(value){ //set up filter here } else{ myGrid.data("kendoGrid").dataSource.filter({}); } });
0
Just
Top achievements
Rank 1
answered on 15 Nov 2012, 02:48 PM
@Pinas: <quote>how about if I want to remove grid's group programatically?  Is it the same?</quote>

 I haven't tried it through .Net code. I prefer JS to do client side filtering & search. :)
Tags
Grid
Asked by
Wonderer
Top achievements
Rank 1
Answers by
Just
Top achievements
Rank 1
Irene
Top achievements
Rank 1
Wonderer
Top achievements
Rank 1
Share this question
or