1

Tried to research this the best I could, but couldn't find a basic example. I have an ASP MVC 3 project with a Telerik Grid. Some of the columns of the grid are hidden because of space constraints. There is a separate UI element that should allow the user to select filter values for all the columns, visible or hidden. I know there must be a way to control the filtered contents of the grid from outside the View on the Client side - this telerik help page states:

filterBy:

Returns the current filter expression of the grid. The initial value is "" (empty string). Check the filter JavaScript method for additional reference.

But I can't find the additional reference. From what I can glean from the web I should do something like this:

var grid = $("#Grid").data("tGrid");

grid.filter("OrderID~eq~10248");

But when it tries to execute I get the following JavaScript error:

grid.filterBy is not a function

What am I doing wrong? And can someone point me to the details of the filterBy method?

EDIT:

I changed my code to:

$("#btnFilter").click(function (e) {
    var grid = $("#Grid").data("tGrid");
    grid.filter("Off_Plan~eq~'No Funds'");
});

Still get the same kind of error: grid.filter is not a function

Obviously I am newbie at telerik. Seems like I am missing some telerik javascript files...? I started this Visual Studio project as a new Telerik MVC Application. The script registrar is there and I've added to the _Layout.cshtml. Groan...

rgwozdz
  • 1,093
  • 2
  • 13
  • 26

1 Answers1

4

I think you're mixing up two things.

There is a property on the grid called filterBy which gets the actual filter.
And there is a method on the grid called filter which filters the grid based on with the given filter expression.

Here is some code:

var grid = $("#Grid").data("tGrid");

var currentFilter = grid.filterBy; //it will be ""

grid.filter("OrderID~eq~10248"); // filtering the grid with OrderID equals 10248

currentFilter = grid.filterBy // now it will return "OrderID~eq~10248"

So that's why grid.filterBy("OrderID~eq~10248"); as a method is not working.

EDIT:

The client side filtering is only working if you've enabled filtering for the grid (see also in doc under Important notice)

@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .Filterable())
nemesv
  • 138,284
  • 16
  • 416
  • 359
  • I tried your solution; see my edit to the original post. Still failing with the same comment...grid.filter is not a function – rgwozdz Mar 27 '12 at 17:40
  • I was able to repro your issue when the grid was not filterable. See my updated answer. If it doesn't solve your problem please post your grid building code. – nemesv Mar 27 '12 at 18:10
  • One last question: do you know of a resource from which I can get a list of the operators that work in filter()? I know about 'eq', and I think I have seen a 'startswith' and maybe a 'substring'...dying to find documentation on this. – rgwozdz Mar 27 '12 at 20:56
  • I think the [telerik documentation of filter](http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#filter) lists all the available `filterOperator` and `filterFunction`. – nemesv Mar 27 '12 at 20:59