Implementation of Typed Method Delegates
- 6 minutes to read
A call to a CardView view model’s CardViewModel.ProcessCustomBinding method in a Controller delegates the implementation of a CardView view model population to Model-layer functions specified with the method’s typed parameters. In general, the CardViewModel.ProcessCustomBinding method can accept four parameters that point to method delegates of specific types. This topic describes the available delegate types and provides you with information on how they can be implemented.
You can refer to the corresponding online demo to see how this scenario is implemented using different method delegates.
Implementation of the CardViewCustomBindingGetDataCardCountHandler delegate
Method implementation is required.
Always implement this method to return the total number of data rows within your model, taking into account applied filtering (if any).
This method accepts the e parameter of the CardViewCustomBindingGetDataCardCountArgs type, which provides you with the following arguments.
Name | Property | Description |
---|---|---|
DataCardCount | CardViewCustomBindingGetDataCardCountArgs.DataCardCount | Gets or sets the total number of data records within a custom model, taking into account the filtering applied within the CardView (if any). |
FilterExpression | CardViewCustomBindingArgsBase.FilterExpression | Gets the filter condition currently applied to the CardView (if any filtering is used). |
State | CardViewCustomBindingArgsBase.State | Gets an object containing information about the current state on the CardView. |
When implementing this delegate, obtain the total number of rows in your model and assign it to the CardViewCustomBindingGetDataCardCountArgs.DataCardCount property. The CardView requires this information to properly calculate the number of pages to be displayed within the pager.
The returned total number should depend upon the filtering conditions (if they were applied to the CardView). Use the CardViewCustomBindingArgsBase.FilterExpression property to obtain the CardView’s filter expression and apply it to your model to obtain the proper number of rows that meet the filter condition. If no filtering is applied, the CardViewCustomBindingArgsBase.FilterExpression property returns an empty string.
The common procedure for implementation of this delegate is provided below.
- Filter your model (if filtering is used) using e.FilterExpression.
- Obtain the model’s total row count and return it to e.DataRowCount.
Generally, the implementation will look as follows.
public static void MyGetDataCardCount(CardViewCustomBindingGetDataCardCountArgs e) {
e.DataCardCount = Model
.ApplyFilter(e.FilterExpression) //Your function that applies a filter to your model
.Count(); //Return the total count of data rows in your model (taking into account the applied filtering, if any)
}
Implementation of the CardViewCustomBindingGetDataHandler delegate
Method implementation is required.
Always implement this method to populate the CardView view model with data cards requested by the extension.
This method accepts the e parameter of the CardViewCustomBindingGetDataArgs type, which provides you with the following arguments.
Name | Property | Description |
---|---|---|
Data | CardViewCustomBindingDataArgsBase.Data | Gets or sets a list of currently requested model characteristics (depending upon which delegated method is being implemented, it can be a list of data cards, or a list of calculated summary values). |
DataCardCount | CardViewCustomBindingGetDataArgs.DataCardCount | Gets the number of currently requested data cards to return. |
FilterExpression | CardViewCustomBindingArgsBase.FilterExpression | Gets the filter condition currently applied to the CardView (if any filtering is used). |
StartDataCardIndex | CardViewCustomBindingGetDataArgs.StartDataCardIndex | Gets the index of the first row in the requested cards list. |
State | CardViewCustomBindingArgsBase.State | Gets an object containing information about the current state on the CardView. |
When implementing this delegate, return the requested data cards via the CardViewCustomBindingDataArgsBase.Data property.
The common procedure for the implementation of this delegate is provided below:
- Filter your model (if filtering is used) using e.State.FilterExpression.
- Sort your model (if sorting is used) using e.State.SortedColumns.
- Obtain the number of rows specified by the e.DataRowCount starting from e.StartDataCardIndex, and return the obtained row list to e.Data.
Generally, the implementation will look as follows.
public static void MyGetData(CardViewCustomBindingGetDataArgs e) {
e.Data = Model
.ApplyFilter(e.State.FilterExpression) //Your function that filters your model
.ApplySorting(e.State.SortedColumns) //Your function that sorts your model
.Skip(e.StartDataCardIndex) //Position on the first required data row
.Take(e.DataRowCount); //Get the number of currently requested data cards (cards of the current page or visible cards of the processed group)
}
Implementation of the CardViewCustomBindingGetSummaryValuesHandler delegate
Method implementation is optional. It is required if you use summaries within the CardView.
Provide implementation for this method to calculate and return values of summaries required within the CardView, taking into account the applied filtering (if any).
This method accepts the e parameter of the CardViewCustomBindingGetSummaryValuesArgs type, which provides you with the following arguments.
Name | Property | Description |
---|---|---|
Data | CardViewCustomBindingDataArgsBase.Data | Gets or sets a list of currently requested model characteristics (depending upon which delegated method is being implemented, it can be a list of data cards, or a list of calculated summary values). |
FilterExpression | CardViewCustomBindingArgsBase.FilterExpression | Gets the filter condition currently applied to the CardView (if any filtering is used). |
State | CardViewCustomBindingArgsBase.State | Gets an object containing information about the current state on the CardView. |
SummaryItems | CardViewCustomBindingGetSummaryValuesArgs.SummaryItems | Gets a list of summary items which are used within the CardView and whose values must be calculated. |
When implementing this delegate, calculate values for summaries from the CardViewCustomBindingGetSummaryValuesArgs.SummaryItems collection, put the calculated summary values in a list, and return this list via the GridViewCustomBindingDataArgsBase.Data property.
The common procedure for the implementation of this delegate is provided below.
- Filter your model (if filtering is used) using e.State.FilterExpression.
- Traverse the e.SummaryItems list, calculate a summary value for each summary item, and return a list of the calculated values to e.Data.
In a general case, the implementation will look as follows.
public static void MyGetSummaryValues(CardViewCustomBindingGetSummaryValuesArgs e) {
var query = Model
.ApplyFilter(e.State.FilterExpression); //Your function that filters your model
var list = new ArrayList();
foreach(var item in e.SummaryItems) {
switch(item.SummaryType) {
case SummaryItemType.Count:
list.Add(query.Count());
break;
case SummaryItemType.Sum:
list.Add(query.Sum(item.FieldName));
break;
}
}
e.Data = list;
}
Implementation of the CardViewCustomBindingGetUniqueHeaderFilterValuesHandler delegate
Method implementation is optional. It is required if you display header filter buttons to use filtering within the CardView.
Provide implementation for this method to return unique values to be displayed in the header filter dropdown list invoked for a column.
This method accepts the e parameter of the CardViewCustomBindingGetUniqueHeaderFilterValuesArgs type, which provides you with the following arguments.
Name | Property | Description |
---|---|---|
Data | CardViewCustomBindingGetUniqueHeaderFilterValuesArgs.Data | Gets or sets a list of unique values contained within a specific data field. |
FieldName | CardViewCustomBindingGetUniqueHeaderFilterValuesArgs.FieldName | Gets the name of the data field whose unique values should be returned. |
FilterExpression | CardViewCustomBindingArgsBase.FilterExpression | Gets the filter condition currently applied to the CardView (if any filtering is used). |
State | CardViewCustomBindingArgsBase.State | Gets an object containing information about the current state on the CardView. |
When implementing this delegate, return a list of unique values obtained from a model data field (specified by the CardViewCustomBindingGetUniqueHeaderFilterValuesArgs.FieldName property) to the CardViewCustomBindingDataArgsBase.Data property. You may also need to take into account the applied filter condition, which can be obtained using the e.FilterExpression (CardViewCustomBindingArgsBase.FilterExpression) or e.State.FilterExpression.
The common procedure for implementation of this delegate is provided below.
- Filter your model (if filtering is used) using e.FilterExpression.
- Obtain a list of unique values from a data field specified by e.FieldName and return this list to e.Data.
In most cases, the implementation will look as follows.
public static void MyGetUniqueHeaderFilterValues(CardViewCustomBindingGetUniqueHeaderFilterValuesArgs e) {
e.Data = Model
.ApplyFilter(e.FilterExpression) //Your function that filters your model
.GetUniqueValues(e.FieldName); //Your function that obtains unique values of the specified data field
}