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

[Solved] Accessing filter descriptor from client side

2 Answers 133 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.
user8721
Top achievements
Rank 1
user8721 asked on 22 Feb 2012, 12:18 PM
Hello,

I am using telerik grid and say i have a column displaying the full name

.Columns(columns =>columns.Bound(s => s.FullName).Title("Name").Filterable();                
      })

When i filter this, and check the filter descriptor object, the member property is having the value "Name" as expected.
Suppose i want to change this value to "FullName" and let it sort by the FullName( and not name), how can i achieve this from the client side,i.e while i'm declaring the columns.

Hope i've made my question understandable.If this topic already exist kindly let me know the link , before removing this thread.

Thanks,
Brian

2 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 22 Feb 2012, 06:01 PM
hi,

I don't know if it is what you want but look at this :

<script type="text/javascript">
        function onDataBinding(e) {
            for (var i in e.filteredColumns) {
                if (e.filteredColumns[i].member == 'Customer.ContactName') {
                    e.filteredColumns[i].member = 'ShipAddress';
                }
            }
        }
 
    </script>
    <% using (Html.Configurator("Filter by ...")
              .PostTo("Filtering", "Grid")
              .Begin())
       { %>
    <p>
        <label for="startsWith">
            <strong>Contact Name</strong> starts with:</label>
        <%= Html.TextBox("startsWith", "Paul") %>
    </p>
    <button class="t-button" type="submit">
        Apply</button>
    <% } %>
    <%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID).Width(120);
            columns.Bound(o => o.Customer.ContactName).Width(200);
            columns.Bound(o => o.ShipAddress);
            columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(100);
        })
        .ClientEvents(e=>e.OnDataBinding("onDataBinding"))
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_Filtering", "Grid"))
        .Pageable()
        .Sortable()
        .Filterable(filtering => filtering
            .Filters(filters => filters
                .Add(o => o.Customer.ContactName).StartsWith((string)ViewData["startsWith"])
        ))
    %>



Now if you make a filter on the "Customer.ContactName" the grid filter the ShipAddress instead (be careful of the type of the filter)


Regards,


0
user8721
Top achievements
Rank 1
answered on 23 Feb 2012, 09:52 AM
Thanks.This is what I'm looking for. I've manipulated the object in the server side. Let me see if your approach works.
Tags
Grid
Asked by
user8721
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
user8721
Top achievements
Rank 1
Share this question
or