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

[Solved] Advanced Grid Functionality: Search Filters

3 Answers 92 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.
Erica
Top achievements
Rank 1
Erica asked on 25 Apr 2012, 12:32 AM
Hello,

I've come to understand that filtering in the MVC grid only filters on current data. I need to return results to the (empty) grid based upon search filters that are entered. These are handled by JQuery and then a grid.ajaxRequest call is made, like so 

function ApplyQuestionFilters(sender) {
    var _grid = $("#QuestionGrid").data("tGrid");
    var search = new Object();
 
    search.IsQuestion = true;
 
    search.QuestionID = $("#QuestionIDSearch").val();
    search.QuestionTitle = $("#QuestionTitleSearch").val();
    search.OriginalURL = $('#OriginalURLSearch').val();
    search.OriginalTitle = $('#OriginalTitleSearch').val();
    search.ChronicID = $('#ChronicIDSearch').val();
    search.TopicID = $('#TopicIDSearch').val();
    search.ChannelID = $('#ChannelIDSearch').val()
   
    _grid.ajaxRequest({ id: -2, filterParams: JSON.stringify(search) });
}


this is my Select statement. I am using Ajax binding.
.Select("GetAllQuestion", "Question", new { id = -1 })

A -1 is passed for ID to indicate that nothing has been specified and nothing is returned to the view. Currently, the Grid supports functionality that takes a single ID and then selects that question and returns that question to the view. There is also a Detail view being implemented that also must be flexible for searching.

So now the functionality of this Grid must be expanded such that multiple filters can be specified and several (Potentially thousands) of results are returned. I created a Search Query class and I'm able to build my LINQ where clause and this is where it gets tricky. I have two issues I currently cannot find a solution for.

1. Paging. I could use EnableCustomBinding, but it apparently only accepts GridCommands as a parameter and I need a lot more than that. Paging is required such that I do not query the DB for all of its data at once. If I am returning 7,000 results, I only want to query for the first 10. This also makes getting the Total count an issue, since it is not known how many results I will be getting but I certainly do not want to request all the results at once.

The other issue will be much easier to resolve once I can find a solution for this issue. I already have an idea for my other issue that involves ViewData["filterParams"] to maintain the Filter parameters but then again I'm not really comfortable with ViewData nor how it works. So if you can help me understand how to use this as well, it would be appreciated. The filterParameters also must be applied on the DetailView when expanded. 

Thanks for the help and let me know if you need any additional information. 

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 27 Apr 2012, 03:25 PM
Hello Erica,

The total variable is required by the Grid paging to work properly - you should search for some performance saving techniques (probably caching or predicting the results of the query).

As for the additional search parameters you need to send to the controller - you should take advantage of the OnDataBinding client event of the Grid and use it to send additional values to the server (check documentation). 
So in your case it should look like this:
function onGridDataBinding(e) {
    var _grid = $(this).data("tGrid");
    var search = new Object();
  
    search.IsQuestion = true;
  
    search.QuestionID = $("#QuestionIDSearch").val();
    search.QuestionTitle = $("#QuestionTitleSearch").val();
    search.OriginalURL = $('#OriginalURLSearch').val();
    search.OriginalTitle = $('#OriginalTitleSearch').val();
    search.ChronicID = $('#ChronicIDSearch').val();
    search.TopicID = $('#TopicIDSearch').val();
    search.ChannelID = $('#ChannelIDSearch').val()
    
    e.data.search = search;//you do not need to serialize it to a string
    // make sure in the controller your argument is also called search
}

You could use this approach for each of your Grids - and they will send the needed information to the server.


All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Erica
Top achievements
Rank 1
answered on 27 Apr 2012, 03:30 PM
hey wow! thanks for responding, but I actually DID get this far in the progress. But thats about as far as I'm currently able to get, unfortunately. To be completely honest, onDataBinding would be great, but there is a fatal flaw. After I update a question , when we return to the screen, all the results dissapear! This is BAD! I tried using the onComplete event but it actually doesnt seem to be raised after an update is finished. Why wouldn't the onComplete event be raised after an ajax call to update? It makes absolutely no sense and would have solved my problems but unfortunately it does not. :(

**Update: got the onComplete event to be raised correctly, but after I rebind the grid from there, it still returns the new view to the controller. Hmm...
0
John
Top achievements
Rank 1
answered on 02 May 2012, 03:15 AM
I am using the following method which works great. Now I am stuck on editing/update:

http://stackoverflow.com/questions/10402252/telerik-mvc-grid-search-edit-and-update-in-ajax-mode
Tags
Grid
Asked by
Erica
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Erica
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or