Skip to main content

Available Binding Delegates

  • 4 minutes to read

To delegate the implementation of a grid view model population to Model-layer functions, call the view model’s GridViewModel.ProcessCustomBinding method in a Controller. This method has several overloads with different sets of parameters. The result of the method call is that the intrinsic grid view model object (GridViewModel) will be populated with the requested data. The view model object can then be passed to the grid’s Partial View as a Model and bound to the GridView via the grid’s GridViewExtension.BindToCustomData method.

Method Overloads

Overload List - C#

public void ProcessCustomBinding( GridViewCustomBindingGetDataRowCountHandler getDataRowCountMethod,
GridViewCustomBindingGetDataHandler getDataMethod );

public void ProcessCustomBinding( GridViewCustomBindingGetDataRowCountHandler getDataRowCountMethod,
GridViewCustomBindingGetDataHandler getDataMethod,
GridViewCustomBindingGetGroupingInfoHandler getGroupingInfoMethod );

public void ProcessCustomBinding( GridViewCustomBindingGetDataRowCountHandler getDataRowCountMethod,
GridViewCustomBindingGetDataHandler getDataMethod,
GridViewCustomBindingGetSummaryValuesHandler getSummaryValuesMethod );

public void ProcessCustomBinding( GridViewCustomBindingGetDataRowCountHandler getDataRowCountMethod,
GridViewCustomBindingGetDataHandler getDataMethod,
GridViewCustomBindingGetSummaryValuesHandler getSummaryValuesMethod,
GridViewCustomBindingGetGroupingInfoHandler getGroupingInfoMethod );

public void ProcessCustomBinding( GridViewCustomBindingGetDataRowCountHandler getDataRowCountMethod,
GridViewCustomBindingGetDataHandler getDataMethod,
GridViewCustomBindingGetSummaryValuesHandler getSummaryValuesMethod,
GridViewCustomBindingGetGroupingInfoHandler getGroupingInfoMethod,
GridViewCustomBindingGetUniqueHeaderFilterValuesHandler getUniqueHeaderFilterValuesMethod );

Method Parameters

The following list describes all available method parameters. Each parameter points to a typed method delegate.

Parameter Name Is Required? Delegated Method Type Description
getDataRowCountMethod Required GridViewCustomBindingGetDataRowCountHandler Always provide an implementation for the delegated method to return the total number of data rows.
getDataMethod Required GridViewCustomBindingGetDataHandler Always provide an implementation for the delegated method to return the data rows requested by the grid.
getSummaryValuesMethod Optional GridViewCustomBindingGetSummaryValuesHandler If you use summaries within the grid, provide an implementation for the delegated method to calculate and return values of summaries required within the grid.
getGroupingInfoMethod Optional GridViewCustomBindingGetGroupingInfoHandler If you use grouping within the grid, provide an implementation for the delegated method to return grouping information for group rows. This grouping information consists of the key (the group value) and the count (the number of data rows within the group), depending on the applied filtering, grouping and sorting.
getUniqueHeaderFilterValuesMethod Optional GridViewCustomBindingGetUniqueHeaderFilterValuesHandler If you use filtering and display header filter buttons within the grid, provide an implementation for the delegated method to return unique values to be displayed in the header filter popup list invoked for a grid column.

Method Usage

The ProcessCustomBinding method’s simple usage scenario is given below - only required method delegates are specified.

public partial class MyController: Controller {
        public ActionResult MyGridView() {
            return View("MyGridView");
        }
        //Standard grid callback requests
        public ActionResult MyGridViewPartial() {
            var gridViewModel = GridViewExtension.GetViewModel("gridView"); //Obtain the grid's state - the grid view model object
            ...
            gridViewModel.ProcessCustomBinding( //Call method with two required parameters
                MyBindingHandlers.MyGetDataRowCount, //Function to return the total number of data rows in a model
                MyBindingHandlers.MyGetData //Function to return data rows requested by the grid
            );
            return PartialView("MyGridViewPartial", gridViewModel);
        }
        ...
    }

The following code sample shows a more versatile way to use the ProcessCustomBinding method.

public partial class MyController: Controller {
        public ActionResult MyGridView() {
            return View("MyGridView");
        }
        //Standard grid callback requests
        public ActionResult MyGridViewPartial() {
            var gridViewModel = GridViewExtension.GetViewModel("gridView");
            if(gridViewModel == null)
                //Initialize the grid state on the first load
                gridViewModel = CreateGridViewModel();
            return MyCustomBindingCore(gridViewModel);
        }
        //Paging operation requests
        public ActionResult MyPagingAction(GridViewPagerState pager) {
            var gridViewModel = GridViewExtension.GetViewModel("gridView");
            gridViewModel.ApplyPagingState(pager); //Update the grid state with the processed paging state
            return MyCustomBindingCore(gridViewModel);
        }
        //Filtering operation requests
        public ActionResult MyFilteringAction(GridViewFilteringState filteringState) {
            var gridViewModel = GridViewExtension.GetViewModel("gridView");
            gridViewModel.ApplyFilteringState(filteringState); //Update the grid state with the processed filtering state
            return MyCustomBindingCore(gridViewModel);
        }
        //Sorting operation requests
        public ActionResult MySortingAction(GridViewColumnState column, bool reset) {
            var gridViewModel = GridViewExtension.GetViewModel("gridView");
            gridViewModel.ApplySortingState(column, reset); //Update the grid state with the processed sorting state
            return MyCustomBindingCore(gridViewModel);
        }
        // Grouping operation requests
        public ActionResult MyGroupingAction(GridViewColumnState column) {
            var gridViewModel = GridViewExtension.GetViewModel("gridView");
            gridViewModel.ApplyGroupingState(column); //Update the grid state with the processed grouping state
            return MyCustomBindingCore(gridViewModel);
        }

        PartialViewResult MyCustomBindingCore(GridViewModel gridViewModel) {
            gridViewModel.ProcessCustomBinding(
                MyBindingHandlers.MyGetDataRowCount, //Function to return the total number of data rows in a model
                MyBindingHandlers.MyGetData, //Function to return the data rows requested by the grid
                MyBindingHandlers.MyGetSummaryValues, //Function to calculate and return the required summary values
                MyBindingHandlers.MyGetGroupingInfo, //Function to return the specified group's grouping information (the group value - key, and the number of data rows within the group - count)
                MyBindingHandlers.MyGetUniqueHeaderFilterValues  //Function to return the unique values of the specified column whose header filter popup list is being invoked
            );
            return PartialView("MyGridViewPartial", gridViewModel);
        }

        static GridViewModel CreateGridViewModel() {
            var viewModel = new GridViewModel();
            viewModel.KeyFieldName = "ID";
            viewModel.Columns.Add("From");
            viewModel.Columns.Add("Subject");
            viewModel.Columns.Add("Sent");
            viewModel.Columns.Add("Size");
            viewModel.Columns.Add("HasAttachment");
            viewModel.TotalSummary.Add(new GridViewSummaryItemState() { FieldName = "Size", SummaryType = SummaryItemType.Sum });
            viewModel.TotalSummary.Add(new GridViewSummaryItemState() { FieldName = "Subject", SummaryType = SummaryItemType.Count });
            viewModel.GroupSummary.Add(new GridViewSummaryItemState() { FieldName = string.Empty, SummaryType = SummaryItemType.Count });
            return viewModel;
        }
    }