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

Grid with filterable and external search inptus

3 Answers 1418 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matelin
Top achievements
Rank 1
Matelin asked on 16 Jan 2015, 09:18 PM
Hi,

I have a sortable, pageable, filterable ajax binding grid with an external search panel inputs and a search button and i need to include these inputs values to
every grid sort, paging and filter actions.

So i need to pass the search input values to the server read action method on every action mentioned above and after that i need to add them to
the DataSourceRequest.Filters object property.

I have search the internet especially for the first part of the issue, and i was able to send additional parameter to the action method as explained 
in your documentation but the the additional parameter get send on the first call only, i don't now if is the default behavior.

Any help.

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 20 Jan 2015, 04:55 PM
Hello Matelin,

Search is practically filtering. Such criteria should be applied to the Grid via its dataSource API:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#fields-dataSource

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-filter

Otherwise the Grid will not "know" that filtering criteria are applied, and this can result in an unexpected behavior or UI.

Regards,
Dimo
Telerik

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

0
Matelin
Top achievements
Rank 1
answered on 20 Jan 2015, 08:17 PM
I have manged to add filters on the server side:

public ActionResult getTableMainData([DataSourceRequest]DataSourceRequest dataSourceRequest, string stringValue, string fromDateValue)
        {
            FilterDescriptor filterDescriptor = new FilterDescriptor();
            filterDescriptor.Value = stringValue;
            filterDescriptor.Member = "stringValue";
            filterDescriptor.Operator = FilterOperator.Contains;
            dataSourceRequest.Filters.Add(filterDescriptor);
 
            var testContext = new TestContext();
            DataSourceResult dataSourceResult = testContext.TableMains.ToDataSourceResult(dataSourceRequest);
 
            return Json(dataSourceResult);
        }

But the java script additional parameters method (wihich will fill "string stringValue, string fromDateValue") get called on
initial read only, so if the search input textbox have an initial value of "test" on the initial read i will get "test", if i change it
to something else and refresh the grid it will send "test" also, is this normal?

i don't understand your comment above, but what you are suggesting is to fill the additional filters on the client side using the data source object? if yes please provide an example.

Regards
  
0
Dimo
Telerik team
answered on 22 Jan 2015, 04:36 PM
Hi Matelin,

My understanding is that "stringValue" is a field, to which the Grid is dataBound, right? If yes, then my idea was that the described scenario does not need sending additional parameters at all. Instead, you should execute a filtering command to the Grid dataSource client-side, which will perform a read request will all required parameters.

gridObject.dataSource.filter( { field: "stringValue", operator: "contains", value: "your textbox value here" });

or in other words:

(based on the Remote DataBinding Grid example, which is part of the offline Kendo UI MVC demo site)

@Html.Kendo().TextBox().Name("ShipNameSearch")
 
@Html.Kendo().Button().Name("GridSeachButton").Events(ev => ev.Click("searchGrid")).Content("Search Ship")
 
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()   
    .Name("grid")
    .Columns(columns => {
        columns.Bound(p => p.ShipName);
    })
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Orders_Read", "Grid"))
     )
)
 
<script>
 
    function searchGrid(e) {
        $("#grid").data("kendoGrid").dataSource.filter({ field: "ShipName", operator: "contains", value: $("#ShipNameSearch").val() });
    }
 
</script>


===

On the other hand, the problem with the repetitive sending of the same parameter in your case can occur if you include parentheses in the data function string, which is incorrect.

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/ajax-binding#pass-additional-data-to-the-action-method

.Read(read => read.Action("Read", "Grid").Data("passDataToGrid")) // correct
 
.Read(read => read.Action("Read", "Grid").Data("passDataToGrid()")) // wrong


Regards,
Dimo
Telerik

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Tags
Grid
Asked by
Matelin
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Matelin
Top achievements
Rank 1
Share this question
or