I couldn't find a direct example on how to achieve a search-page with several search-criterias to filter the grid result. An example of a search-page could be this from google http://www.google.com/advanced_search?hl=en
I saw the external service example (of twitter) but maybe exists something more straight.
Cheers
7 Answers, 1 is accepted
I have attached a sample project showing how to use the grid client-side API in order to filter it based on the value of some textbox. Here is the most interesting part of the example
<
label
for
=
"search"
>
Company Name:</
label
>
<
input
type
=
"text"
id
=
"search"
/>
<%=
Html.Telerik().Grid<
MvcApplication3.Models.Customer
>(Model)
.Name("Grid")
.Columns(columns => columns.Add(c => c.CompanyName))
.Pageable()
.Filterable()
%>
<%= Html.Telerik().ScriptRegistrar() %>
<script type=
"text/javascript"
>
$(
'#search'
).keydown(
function
(e) {
if
(e.keyCode == 13) {
var
grid = $(
'#Grid'
).data(
'tGrid'
);
grid.filter(
"substringof(CompanyName,'"
+ $(
this
).val() +
"')"
);
}
});
</script>
Regards,
Atanas Korchevthe Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
- Customers Table
- Total rows in table: 100,000
- Page Size: 20
I am not sure I understand your requirements correctly. Are they similar to the scenario demonstrated in this online example? If not please elaborate.
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Atanas, I think that the main question in the example you provide to us: the filtering is taking place in the Client-side or Server-side?
Thanks
The filtering is taking place on the server-side. The following code:
ordersGrid.rebind({calls the server :
customerID: customerID
});
[GridAction]
public ActionResult _RelatedGrids_Orders(string customerID)
{
customerID = customerID ?? "ALFKI";
return View(new GridModel<Order>
{
Data = GetOrdersForCustomer(customerID)
});
}
and passes the customerID value. The GetOrdersForCustomer returns the filtered orders and then the action method returns JSON to which the grid binds on the client-side.
I hope this helps,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Is it possible to add another filter criteria?
I'm trying to search several columns at the same time, using this code:
<
script
type
=
"text/javascript"
><
br
> $('#search').keydown(function(e) {<
br
> if (e.keyCode == 13) {<
br
> var grid = $('#Customers').data('tGrid');<
br
> var searchTerm = $(this).val();<
br
> grid.filter("substringof(FirstName,'" + searchTerm + "')" + "~and~substringof(LastName,'" + searchTerm + "')" + "~and~substringof(EmailAddress,'" + searchTerm + "')");
<
br
> }<
br
> });<
br
></
script
>
but I need "or" operator instead of "and". Changing "~and~" with "~or~" is not working.
Any suggestions?
Best regards,
Bojan
<%
= Html.Telerik().Grid(new List<MonitorSearchResult>())
.Name(
"events")
.Columns(colums =>
{
colums.Bound(c => c.TransmissionEventId).Title(
"Event Id");
colums.Bound(c => c.EventStatusDescription).Title(
"status");
colums.Bound(c => c.Direction).Title(
"Direction");
})
.DataBinding(d => d.Ajax().Select(
"Search", "Monitor"))
.Sortable()
%>
<script type="text/javascript">
$(document).ready(
function () {
$(
'#btnSearch').click(function () {
var grid = $('#events').data('tGrid');
var searchModel = {
TransmissionAccountId: $(
'#SelectedCriteria_TransmissionAccountId').val(),
};
grid.rebind(searchModel);
return false;
});
});
</script>
The problem is Grid is undefined and I cannot figure out why! Please help.
$(
'#events')
is found just not the .data('tData') part of it.