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

[Solved] Setting Filter on load

5 Answers 218 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.
John
Top achievements
Rank 2
John asked on 18 Jul 2010, 07:49 AM
Hi

I have one small issue when loading a new grid.  I am trying to load the last used filters on initial load but a getting a undefined value for the grid.  I have tried both in the OnLoad and Document ready but has the same result.

Here is a snippet of the grid definition and Java.  I am saving the filter in a hidden field which is retuning the value as expected.  I am using VS2010 and 2010.1.591.40 (MVC2).  I hope that is clear.

Also once i have retreived the filter is it possible to apply it to my query to limit it as it does for teh Ajex call.?

John



    <%: Html.HiddenFor(Function(model) model.Filter)%>
    <script type="text/javascript">
        $(document).ready(function () {
            var grid = $('#MyBatchBarcodesGrid').data('tGrid');
            grid.filter('<%= model.filter %>');
        });
    </script
    <script type="text/javascript">
        function onDataBinding(e) {
            var grid = $(this).data('tGrid');
            $('#Filter').attr('value', grid.filterBy);
        }
        function onLoad(e) {
            var grid = $(this).data('tGrid');
            //grid.filter('<%= model.filter %>');
        }
    </script
  
<%= Html.Telerik() _
            .Grid(Of AIMSWeb.MyBatchBarcodesItemViewModel)() _
            .Name("MyBatchBarcodesGrid") _
            .Scrollable(Function(scrolling) scrolling.Height(500)) _
            .Pageable(Function(paging) paging.PageSize(20)) _
            .DataKeys(Function(keys) keys.Add(Function(o) o.JobID)) _
            .ClientEvents(Function(Events) Events.OnDataBinding("onDataBinding")) _
            .Columns(Sub(columns)
                         columns.Bound(Function(o) o.JobID).Format(Html.IconActionLink("~/Content/Images/icons/icon_pdf.gif", "Print Barcode", "BatchBarcodePrint", "My", New With {.id = "{0}"})).Encoded(False).Title("").Filterable(False).Sortable(False).Width(38)
                         columns.Bound(Function(o) o.JobID).Width(60).Title("ID")
                         columns.Bound(Function(o) o.Claimant1).Width(150).Title("Name")
                         columns.Bound(Function(o) o.Claimant1Detail).Width(300).Title("Address")
                         columns.Bound(Function(o) o.Claimant1PostCode).Width(60).Title("Post Code")
                         columns.Bound(Function(o) o.Claimant1PhoneGeneral).Width(100).Title("Home Phone")
                         columns.Bound(Function(o) o.Claimant1PhoneWork).Width(100).Title("Work Phone")
                         columns.Bound(Function(o) o.Claimant1PhoneMobile).Width(100).Title("Mobile")
                     End Sub) _
            .DataBinding(Sub(dataBinding)
                             dataBinding.Ajax().Select("_AjaxBatchBarcodes", "My")
                         End Sub) _
            .Scrollable(Function(scrolling) scrolling.Enabled(True)) _
            .Sortable(Function(sorting) sorting.Enabled(True)) _
            .Pageable(Function(paging) paging.Enabled(True)) _
            .Filterable(Function(filtering) filtering.Enabled(True)) _
            .Groupable(Function(grouping) grouping.Enabled(True)) _
            .Footer(True)%>

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Jul 2010, 07:23 AM
Hello John,

You can try the sample project attached in this forum thread. It shows how to load the grid filter.

The reason it is not working in your case is that the grid object is not yet created during the OnLoad event. We are considering this a bug and will addressed it in the Q2 release (it is in fact addressed in the beta). The quick workaround is to use setTimeout:

function onLoad(e) {
   setTimeout(function() {
     var grid = $(this).data('tGrid');
     grid.filter('<%= model.filter %>');
   }, 10);
}


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
0
John
Top achievements
Rank 2
answered on 20 Jul 2010, 03:11 AM
Hi Atanas

That worked a treat.

One last question, is there a way of using the filter on the query that is used in the Ajax call to limit what i output in a seperate report. What i am trying to do is limit what is output a repoert by what is displayed in the grid not the orginal query. 

I hope that is clear.

Thanks again

John
0
Atanas Korchev
Telerik team
answered on 20 Jul 2010, 07:17 AM
Hello John,

If you want to use the filter of the ajax query you need to simply add a string parameter named "filter" to the action method which binds the grid.

[GridAction]
public ActionResult _AjaxBinding(string filter)


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
0
John
Top achievements
Rank 2
answered on 20 Jul 2010, 07:32 AM
Hi Atanas

Thanks for the reply. I dont i worded my requirement well so will give it another go.

Since I now have the last used filter returned from tha page I now want to apply it to the query and pass the query results to a report so the same filerting is applied to the query as to how it has been displayed in the grid.  Is there a method i can use to do this in one of the telerik libararies.

I hope that is clearer.

John
0
Atanas Korchev
Telerik team
answered on 20 Jul 2010, 07:50 AM
Hi John,

The only method which we provide is the ToGridModel extension method. You can use it by importing Telerik.Web.Mvc.Extensions. A working case can be seen in the web service binding demo. Check the implementation of any of the web services (in the codeviewer).

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
John
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
John
Top achievements
Rank 2
Share this question
or