Inheriting from JqGridHelper in Lib.Web.Mvc plugin to override a property keeps throwing errors

408 Views Asked by At

I am using the Lb.Web.Mvc plugin from TPeczek and it has been working great, I have noticed that in all of my grids I seem to be overriding the default value so I wanted to permanently change these settings to save my self from having to always type them out. According to TPeczek the only way to do that is to

deliver your own JqGridOptions and use proper JqGridHelper

so the first thing I did was look at the stock JqGridHelper class and copy/past it into my new class MyJqGridHelper but that failed with the error

must declare a body because it is not marked abstract, extern, or partial

Here is the code I was using that gave the error:

public class JqGridHelper<TModel> : IJqGridHelper
{
    public JqGridHelper(JqGridOptions<TModel> options, object subgridHelper = null);

    public JqGridHelper(string id = "Grid", string afterInsertRow = null, string afterEditCell = null, string afterRestoreCell = null, string afterSaveCell = null, string afterSubmitCell = null, string altClass = "ui-priority-secondary", bool altRows = false, bool autoEncode = false, bool autoWidth = true, string beforeRequest = null, string beforeSelectRow = null, string beforeEditCell = null, string beforeSaveCell = null, string beforeSubmitCell = null, string caption = null, int cellLayout = 5, bool cellEditingEnabled = false, JqGridCellEditingSubmitModes cellEditingSubmitMode = JqGridCellEditingSubmitModes.Remote, string cellEditingUrl = null, string dataString = null, JqGridDataTypes dataType = JqGridDataTypes.Json, bool deepEmpty = false, JqGridLanguageDirections direction = JqGridLanguageDirections.Ltr, JqGridDynamicScrollingModes dynamicScrollingMode = JqGridDynamicScrollingModes.Disabled, int dynamicScrollingTimeout = 200, string editingUrl = null, string emptyRecords = "No resultes found.", bool expandColumnClick = true, string expandColumn = null, int? height = null, string errorCell = null, string formatCell = null, bool footerEnabled = false, bool gridView = false, bool groupingEnabled = false, JqGridGroupingView groupingView = null, bool headerTitles = false, bool hidden = false, bool hiddenEnabled = true, bool ignoreCase = true, JqGridJsonReader jsonReader = null, string loadBeforeSend = null, string loadError = null, string loadComplete = null, bool loadOnce = true, JqGridMethodTypes methodType = JqGridMethodTypes.Get, JqGridMultiKeys? multiKey = null, bool multiBoxOnly = false, bool multiSelect = false, int multiSelectWidth = 20, bool multiSort = false, string gridComplete = null, string onCellSelect = null, string onDoubleClickRow = null, string onHeaderClick = null, string onInitGrid = null, string onPaging = null, string onRightClickRow = null, string onSelectAll = null, string onSelectCell = null, string onSelectRow = null, string onSortCol = null, bool pager = true, JqGridParametersNames parametersNames = null, object postData = null, string postDataScript = null, string resizeStart = null, string resizeStop = null, string rowAttributes = null, List<int> rowsList = null, int rowsNumber = 20, bool rowsNumbers = false, int rowsNumbersWidth = 25, bool shrinkToFit = true, int scrollOffset = 18, string serializeCellData = null, string serializeGridData = null, string serializeSubGridData = null, bool sortable = false, string sortingName = "", JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc, bool subgridEnabled = false, JqGridSubgridModel subgridModel = null, object subgridHelper = null, string subgridUrl = null, int subgridColumnWidth = 20, string subGridBeforeExpand = null, string subGridRowColapsed = null, string subGridRowExpanded = null, bool topPager = false, bool treeGridEnabled = false, JqGridTreeGridModels treeGridModel = JqGridTreeGridModels.Nested, string url = null, bool userDataOnFooter = false, bool viewRecords = true, int? width = null);

    public string FilterGridId { get; }

    public string Id { get; }

    public string PagerId { get; }

    public JqGridHelper<TModel> AddActionsColumn(string name, int position = 0, int width = 60, bool editButton = true, bool deleteButton = true, bool useFormEditing = false, JqGridInlineNavigatorActionOptions inlineEditingOptions = null, JqGridNavigatorEditActionOptions formEditingOptions = null, JqGridNavigatorDeleteActionOptions deleteOptions = null);

    public JqGridHelper<TModel> AddNavigatorButton(JqGridNavigatorButtonOptions options);

    public JqGridHelper<TModel> AddNavigatorButton(string caption = "NewButton", string icon = "ui-icon-newwin", string onClick = null, JqGridNavigatorButtonPositions position = JqGridNavigatorButtonPositions.Last, string toolTip = "", string cursor = "pointer", bool cloneToTop = false);

    public JqGridHelper<TModel> AddNavigatorSeparator(JqGridNavigatorSeparatorOptions options);

    public JqGridHelper<TModel> AddNavigatorSeparator(string @class = "ui-separator", string content = "", bool cloneToTop = false);

    public JqGridHelper<TModel> FilterGrid(List<JqGridFilterGridRowModel> model = null, JqGridFilterGridOptions options = null);

    public JqGridHelper<TModel> FilterToolbar(JqGridFilterToolbarOptions options = null);

    public MvcHtmlString GetFilterGridHtml();

    public MvcHtmlString GetHtml();

    public MvcHtmlString GetJavaScript();

    public MvcHtmlString GetPagerHtml();

    public MvcHtmlString GetTableHtml();

    public JqGridHelper<TModel> InlineNavigator(JqGridInlineNavigatorOptions options);

    public JqGridHelper<TModel> Navigator(JqGridNavigatorOptions options, JqGridNavigatorEditActionOptions editActionOptions = null, JqGridNavigatorEditActionOptions addActionOptions = null, JqGridNavigatorDeleteActionOptions deleteActionOptions = null, JqGridNavigatorSearchActionOptions searchActionOptions = null, JqGridNavigatorViewActionOptions viewActionOptions = null);

    public JqGridHelper<TModel> SetFooterData(IDictionary<string, object> data, bool useFormatters = true);

    public JqGridHelper<TModel> SetFooterData(object data, bool useFormatters = true);

    public JqGridHelper<TModel> SetFrozenColumns();

    public JqGridHelper<TModel> SetGroupHeaders(IEnumerable<JqGridGroupHeader> groupHeaders, bool useColSpanStyle = false);
}

I then tried to just inherit from the base JqGridHelper and just override the once property I wanted to change but that gave me the error that I must declare a return type, which I have no idea what would be since the original JqGridHelper does not return a type either.

public class MyJqGridHelper<TModel>: JqGridHelper<TModel>
{
    public JqGridHelper(string id = "Grid",string afterInsertRow = null,string afterEditCell = null,string afterRestoreCell = null,string afterSaveCell = null,string afterSubmitCell = null,string altClass = "ui-priority-secondary",bool altRows = false,bool autoEncode = false,bool autoWidth = true,string beforeRequest = null,string beforeSelectRow = null,string beforeEditCell = null,string beforeSaveCell = null,string beforeSubmitCell = null,string caption = null,int cellLayout = 5,bool cellEditingEnabled = false,JqGridCellEditingSubmitModes cellEditingSubmitMode = JqGridCellEditingSubmitModes.Remote,string cellEditingUrl = null,string dataString = null,JqGridDataTypes dataType = JqGridDataTypes.Json,bool deepEmpty = false,JqGridLanguageDirections direction = JqGridLanguageDirections.Ltr,JqGridDynamicScrollingModes dynamicScrollingMode = JqGridDynamicScrollingModes.Disabled,int dynamicScrollingTimeout = 200,string editingUrl = null,string emptyRecords = "No resultes found.",bool expandColumnClick = true,string expandColumn = null,int? height = null,string errorCell = null,string formatCell = null,bool footerEnabled = false,bool gridView = false,bool groupingEnabled = false,JqGridGroupingView groupingView = null,bool headerTitles = false,bool hidden = false,bool hiddenEnabled = true,bool ignoreCase = true,JqGridJsonReader jsonReader = null,string loadBeforeSend = null,string loadError = null,string loadComplete = null,bool loadOnce = true,JqGridMethodTypes methodType = JqGridMethodTypes.Get,JqGridMultiKeys? multiKey = null,bool multiBoxOnly = false,bool multiSelect = false,int multiSelectWidth = 20,bool multiSort = false,string gridComplete = null,string onCellSelect = null,string onDoubleClickRow = null,string onHeaderClick = null,string onInitGrid = null,string onPaging = null,string onRightClickRow = null,string onSelectAll = null,string onSelectCell = null,string onSelectRow = null,string onSortCol = null,bool pager = true,JqGridParametersNames parametersNames = null,object postData = null,string postDataScript = null,string resizeStart = null,string resizeStop = null,string rowAttributes = null,List<int> rowsList = null,int rowsNumber = 20,bool rowsNumbers = false,int rowsNumbersWidth = 25,bool shrinkToFit = true,int scrollOffset = 18,string serializeCellData = null,string serializeGridData = null,string serializeSubGridData = null,bool sortable = false,string sortingName = "",JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc,bool subgridEnabled = false,JqGridSubgridModel subgridModel = null,object subgridHelper = null,string subgridUrl = null,int subgridColumnWidth = 20,string subGridBeforeExpand = null,string subGridRowColapsed = null,string subGridRowExpanded = null,bool topPager = false,bool treeGridEnabled = false,JqGridTreeGridModels treeGridModel = JqGridTreeGridModels.Nested,string url = null,bool userDataOnFooter = false,bool viewRecords = true,int? width = null);
}

I tried to change it to a return type of TModel but that brings me back to the declare body error I was first getting. At this point I am completely lost on how the heck I am supposed to be able to inherit from the stock class to be able to use my own.

1

There are 1 best solutions below

2
On BEST ANSWER

actually public JqGridHelper returning something, but you cant see the code that implemented in there. but here is the link if you want to see the full source code of JqGridHelper https://github.com/tpeczek/Lib.Web.Mvc/blob/master/Lib.Web.Mvc/JQuery/JqGrid/JqGridHelper.cs. also if you have a tool like resharper, you can decompile the plugin and may see the full source code. you could create your custom constructor to calling the jqgridhelper class constructor and adding your custom parameter. for example:

public class MyJqGridHelper<TModel>: JqGridHelper<TModel>
{
    public MyJqGridHelper(string id="Grid",string afterInsertRow = null,string afterEditCell = null,string afterRestoreCell = null,string afterSaveCell = null,string afterSubmitCell = null,string altClass = "ui-priority-secondary",bool altRows = false,bool autoEncode = false,bool autoWidth = true,string beforeRequest = null,string beforeSelectRow = null,string beforeEditCell = null,string beforeSaveCell = null,string beforeSubmitCell = null,string caption = null,int cellLayout = 5,bool cellEditingEnabled = false,JqGridCellEditingSubmitModes cellEditingSubmitMode = JqGridCellEditingSubmitModes.Remote,string cellEditingUrl = null,string dataString = null,JqGridDataTypes dataType = JqGridDataTypes.Json,bool deepEmpty = false,JqGridLanguageDirections direction = JqGridLanguageDirections.Ltr,JqGridDynamicScrollingModes dynamicScrollingMode = JqGridDynamicScrollingModes.Disabled,int dynamicScrollingTimeout = 200,string editingUrl = null,string emptyRecords = "No resultes found.",bool expandColumnClick = true,string expandColumn = null,int? height = null,string errorCell = null,string formatCell = null,bool footerEnabled = false,bool gridView = false,bool groupingEnabled = false,JqGridGroupingView groupingView = null,bool headerTitles = false,bool hidden = false,bool hiddenEnabled = true,bool ignoreCase = true,JqGridJsonReader jsonReader = null,string loadBeforeSend = null,string loadError = null,string loadComplete = null,bool loadOnce = true,JqGridMethodTypes methodType = JqGridMethodTypes.Get,JqGridMultiKeys? multiKey = null,bool multiBoxOnly = false,bool multiSelect = false,int multiSelectWidth = 20,bool multiSort = false,string gridComplete = null,string onCellSelect = null,string onDoubleClickRow = null,string onHeaderClick = null,string onInitGrid = null,string onPaging = null,string onRightClickRow = null,string onSelectAll = null,string onSelectCell = null,string onSelectRow = null,string onSortCol = null,bool pager = true,JqGridParametersNames parametersNames = null,object postData = null,string postDataScript = null,string resizeStart = null,string resizeStop = null,string rowAttributes = null,List<int> rowsList = null,int rowsNumber = 20,bool rowsNumbers = false,int rowsNumbersWidth = 25,bool shrinkToFit = true,int scrollOffset = 18,string serializeCellData = null,string serializeGridData = null,string serializeSubGridData = null,bool sortable = false,string sortingName = "",JqGridSortingOrders sortingOrder = JqGridSortingOrders.Asc,bool subgridEnabled = false,JqGridSubgridModel subgridModel = null,object subgridHelper = null,string subgridUrl = null,int subgridColumnWidth = 20,string subGridBeforeExpand = null,string subGridRowColapsed = null,string subGridRowExpanded = null,bool topPager = false,bool treeGridEnabled = false,JqGridTreeGridModels treeGridModel = JqGridTreeGridModels.Nested,string url = null,bool userDataOnFooter = false,bool viewRecords = true,int? width = null)
    : base (id,afterInsertRow,afterEditCell,afterRestoreCell,afterSaveCell,afterSubmitCell,altClass,altRows ,autoEncode,autoWidth,beforeRequest,beforeSelectRow,beforeEditCell,beforeSaveCell,beforeSubmitCell,  caption, cellLayout, cellEditingEnabled, cellEditingSubmitMode,cellEditingUrl,dataString,dataType,deepEmpty,direction,  dynamicScrollingMode, dynamicScrollingTimeout, editingUrl, emptyRecords, expandColumnClick,  expandColumn ,height, errorCell, formatCell, footerEnabled, gridView, groupingEnabled , groupingView, headerTitles , hidden  ,  hiddenEnabled , ignoreCase , jsonReader , loadBeforeSend , loadError , loadComplete , loadOnce , methodType , multiKey , multiBoxOnly, multiSelect , multiSelectWidth , multiSort , gridComplete , onCellSelect , onDoubleClickRow , onHeaderClick , onInitGrid , onPaging , onRightClickRow , onSelectAll , onSelectCell , onSelectRow , onSortCol , pager , parametersNames , postData , postDataScript , resizeStart , resizeStop , rowAttributes , rowsList , rowsNumber , rowsNumbers , rowsNumbersWidth , shrinkToFit , scrollOffset , serializeCellData , serializeGridData , serializeSubGridData , sortable , sortingName , sortingOrder , subgridEnabled , subgridModel , subgridHelper , subgridUrl , subgridColumnWidth , subGridBeforeExpand , subGridRowColapsed , subGridRowExpanded , topPager  , treeGridEnabled , treeGridModel  , url , userDataOnFooter , viewRecords ,  width )
    {
        //other stuff here, if you want to do something different after calling base constructor
    }
}