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

[Solved] Filter Grid from External Component

7 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Victor
Top achievements
Rank 1
Victor asked on 24 Mar 2011, 05:47 PM
Hi!

I am implementing an external component to filter the grid control. The functionality will be similair to http://demos.telerik.com/aspnet-mvc/razor/Splitter/NestingComponents but with much more complex filtering options of course.

What is the best/simplest way to update the grid via ajax? I can without any problems replace the entire grid, but i would like to update the values only if at all possible. Any guidance?

Thanks in advance!
/Victor

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 09:04 AM
Hi Victor,

 The filter JavaScript method is best suited for this task.

Kind regards,
Atanas Korchev
the Telerik team
0
Victor
Top achievements
Rank 1
answered on 25 Mar 2011, 09:26 AM
Hi!

Thanks for the reply, but I think you misunderstood, allow me to clarify. Basically I have a complex filtering component that filters on properties only available server-side. So:
  1. I render the grid based on a full List<Person> in the right pane and a custom filtering component in the left
  2. I select some filter properties
  3. An ajax call is sent to a custom action method
  4. In that action method I generate a new List<Person> based on the new filtering criteria
  5. I send some feedback to the filtering component in a Json reply
  6. I update the filtering component

The thing is that I in steps 5 and 6 want to also send the newly generated List<Person> and, using that, update the grid. Is it possible to take advantage of the existing server-side and/or client-side logic to make this happen? I also realize now that I _have_ to do it in some "telerik-native" way, since I also want support for paging/sorting/etc (which means making sure the grid sends the custom filtering data in later requests)

Any ideas on how to solve this will be greatly appreciated.

/Victor
0
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 10:03 AM
Hi Victor,

You can perhaps bind the grid to the filtered datasource. The grid will do the paging and sorting for you. The other option is to try and use the grid server filtering API instead. In both cases however you will need to update the whole grid through Ajax. The only option not to update the whole grid is to use the filter JavaScript method.

Regards,
Atanas Korchev
the Telerik team
0
Victor
Top achievements
Rank 1
answered on 25 Mar 2011, 10:40 AM
Ok thanks, I certainly realize the problem. I guess what I really need is to rebind or recreate fully the grid with some filtering attributes as "constant arguments" to the _Select function. However I cannot see any way to change the binding urls after initialization?

One option seems to be to override the OnDataBinding event and (looking at the twitter example) setting the url variable to one respecting the custom filtering options. However I cant see how to get (and respect) internal filtering values, sorting etc - is that possible? When all that is done, all that seems that it needs to be done is either calling the ajaxRequest method (which is also used in sorts etc) or to call the dataBind method (to make it possible to get all data in one request).

Would this work?
/Victor
0
Accepted
Atanas Korchev
Telerik team
answered on 25 Mar 2011, 10:49 AM
Hello Victor,

 You can perhaps send custom values through the OnDataBinding event:

function onDataBinding(e) {
    e.data = { custom: "value" };
}

if you call the ajaxRequest method the grid will be refreshed using the current state information (paging, sorting etc). The rebind method will reset the grid (first page, no sort expression).

Regards,
Atanas Korchev
the Telerik team
0
Victor
Top achievements
Rank 1
answered on 04 Apr 2011, 08:32 AM
Hi again!

Manually binding data to the grid using
grid.dataBind(jsonData.gridData);
works very well (jsonData is the ajax response and jsonData.gridData is an onobject containing the grid data (serialized from a list of the class the grid is initially bound to. Of course no grid functions (sort/page/...) works, but that's expected.

Next step is to employ the OnDataBinding event in some way. How do I subscribe to that event i js code? That is - I only want to subscribe to it when the filtering component is fully initialized, and I also want to do it from within that code, is that possible?

/Victor
0
Accepted
Atanas Korchev
Telerik team
answered on 04 Apr 2011, 03:34 PM
Hello Victor,

This should work:

$("#Grid").bind("dataBinding", function() {
    alert("OnDataBinding")
});


Regards,

Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Victor
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Victor
Top achievements
Rank 1
Share this question
or