GridClientDataDemo.aspx
<div class="bar">
<% Txtsearch.TextBox().Placeholder("search ...").CssClass("searchtxt"); %>
<awe:Ocon runat="server" ID="Txtsearch" />
<span class="hint"> you can search multiple columns at the same time (try 'jer tav')</span>
</div>
<% GridClientData.Grid()
.DataFunc("getGridData")
.Height(350)
.Mod(o => o.PageInfo().PageSize().ColumnsSelector())
.Persistence(Persistence.View)
.Resizable()
.Reorderable()
.Parent(Txtsearch.ClientID, "search", false)
.Columns(
new Column { Bind = "Id", Width = 75, Groupable = false, Resizable = false },
new Column { Bind = "Person" },
new Column { Bind = "FoodName", Header = "Food" },
new Column { Bind = "Location" },
new Column { Bind = "Date", Width = 120 },
new Column { Bind = "CountryName", Header = "Country" },
new Column { Bind = "ChefName", Header = "Chef" }); %>
<awe:Ocon runat="server" ID="GridClientData" />
<script>
// client data source
var lunches = <%=DemoUtils.Encode(Db.Lunches.Take(300).Select(o => new
{
o.Id,
o.Person,
FoodName = o.Food.Name,
o.Location,
o.Price,
CountryName = o.Country.Name,
ChefName = o.Chef.FirstName + " " + o.Chef.LastName,
o.Date,
DateStr = o.Date.ToShortDateString()
})) %>;
function getGridData(sgp) {
var gp = aweUtils.getGridParams(sgp);
var words = gp.search.split(" ");
var regs = $.map(words, function(w) { return new RegExp(w, "i"); });
var regslen = regs.length;
// filter func, will be passed to gridModelBuilder
function filter(list) {
var res = $.grep(list, function(o) {
var matches = 0;
$.each(regs, function(_, reg) {
if(reg.test(o.FoodName) || reg.test(o.Person) || reg.test(o.Location) || reg.test(o.CountryName)
|| reg.test(o.ChefName)) matches++;
});
return regslen == matches;
});
return res;
}
function map(o) { return { Id: o.Id, Person: o.Person, FoodName: o.FoodName, Location: o.Location,
Date: o.DateStr, CountryName: o.CountryName, ChefName: o.ChefName }; };
return aweUtils.gridModelBuilder(
{
key:"Id",
gp: gp,
items: filter(lunches),
map:map,
// replace default group header value for Date
getHeaderVal:{ Date: function(o){ return o.DateStr; } }
});
}
$(function() {
$('#<%=Txtsearch.ClientID %>').keyup(function() {
$('#<%=GridClientData.ClientID %>').data('api').load();
});
});
</script>