For developers: Render additional items
Using RadGrid Binder, you can generate additional items like if you want to render dynamic header / footer.
Render additional items using RadGrid Binder
Using RadGrid Binder, you can generate addtional items like if you want to render dynamic header / footer.
The idea is pretty simple, binder fires a OnClientDataBound after binding of all the data item is complete, there you can access the "sender" parameters for additional properties, by which you can dynamic change your content according to the current selection or data.
function
OnSectionDataBound(sender, args) {
var
count = sender.get_itemCount();
var
context = sender.get_context();
if
(count > 0) {
if
(context[
"Title"
]) {
$(
"#<%= lblHeader.ClientID %>"
).text(context[
"Title"
]);
}
if
(context[
"Description"
]) {
$(
"#<%= lblDesc.ClientID %>"
).text(context[
"Description"
]);
}
}
}
So, here you can see that there are two properties that can be useful
- get_itemCount() - Returns the virtual count of the grid.
- get_context - Returns an array of custom items, that are returned as key-value pair.
Here, in the example from server-side , i have dymaically sent the header title and description. The way i populated the context follows.
public
CollectionContext<MyObject> SomeMethod(
string
param1,
string
provider)
{
IList<UISectionItem> list = GetMyItems();
var collectionContext =
new
CollectionContext<UISectionItem>(list)
{
TotalCount = list.Count
};
collectionContext.Context =
new
Dictionary<
string
,
string
>();
collectionContext.Context.Add(
"Title"
,
"My Title"
);
collectionContext.Context.Add(
"Description"
,
"My description"
);
return
collectionContext;
}
As, it seems its nothing but a dictionary of strings, that is set to the CollectionContext and which is finally passed to the client via RadGridBinder.