首先加载jqgrid如何加载特定记录的页面?

时间:2017-11-13 07:52:40

标签: jqgrid

使用Jquery.Jqgrid v4.4.4      我的状态网格中有10个页面,我想显示在第一个jqgrid加载中保存状态名称“Tamilnadu”的页面。不要在第一页上显示状态,需要在第一次显示该页面。

编辑:我的Jqgrid代码,这里我有'State'列包含10多个页面,在其中一个'Tamilnadu'状态记录中。请帮我详细说明如何在首次加载时加载网页。

// Setting up County Grid properties
$(function () {
    $("#CountyGrid").jqGrid({
        url: '/ControlTables/GetCountyResult',
        datatype: "json",
        contentType: "application/json; charset-utf-8",
        mtype: 'Get',
        colNames: ['CountyIdentifier', 'Active', 'State', 'County', 'County Number', AddNewBtn],
        colModel: [
        {
            Key: true, name: 'CountyIdentifier', index: 'CountyIdentifier', width: 16, editable: false, sortable: true, align: "left", classes: "grid-col",
            hidden: true, displayName: "CountyIdentifier"
        },
        {
            name: 'ActiveFlag', index: 'ActiveFlag', width: 4, align: 'center', editable: true,
            edittype: 'checkbox', editoptions: { value: "True:False", defaultValue: "True" }, formatter: "checkbox", displayName: "Active"
        },
        {
            name: 'StateIdentifier', index: 'StateIdentifier', editable: true, formatter: 'select', sortable: true,
            edittype: 'select', width: 19, align: "left", classes: "grid-col", editoptions: { style: "height:23px;" }, displayName: "State", valueField: "StateText",
        },
        {
            name: 'CountyText', index: 'CountyText', width: 19, editable: true, sortable: true, align: "left", classes: "grid-col",
            editoptions: { style: "height:23px;", maxlength: "48", dataInit: function (el) { $(el).css('text-transform', 'uppercase'); } }, displayName: "County"
        },
        {
            name: 'CountyNumber', index: 'CountyNumber', width: 7, editable: true, sortable: true, align: "left", classes: "grid-col",
            editoptions: { style: "height:23px;", maxlength: "5" }, displayName: "County Number"
        },
        {
            name: "action", index: "action", sortable: false, editable: false, align: "center", width: "7", displayName: "Action"
        },
        ],

        // Call select row function
        onSelectRow: function (id) {
            if (onPagingLastSel) {
                $('#CountyGrid').jqGrid('resetSelection', lastsel, true);
                onPagingLastSel = false;
            }
            rowSelect(id);
        },

        onPaging: function () {
            //Prompt to save pending changes when the user try to navigate Next/Previous/Front/Last page.
            if (lastsel != null) {
                $('#CountyGrid').jqGrid('saveRow', lastsel, {});
                var editrowData = jQuery("#CountyGrid").getRowData(lastsel);
                var editRow_ActiveFlag = editrowData['ActiveFlag']
                var editRow_StateIdentifier = editrowData['StateIdentifier']
                var editRow_CountyText = editrowData['CountyText']
                var editRow_CountyNumber = editrowData['CountyNumber']                
                $('#CountyGrid').jqGrid('editRow', lastsel, {});
                if ((lastsel_StateIdentifier != editRow_StateIdentifier && editRow_StateIdentifier != undefined)||
                    (lastsel_CountyText != editRow_CountyText && editRow_CountyText != undefined) ||
                    (lastsel_CountyNumber != editRow_CountyNumber && editRow_CountyNumber != undefined) ||
                    (lastsel_ActiveFlag != editRow_ActiveFlag && editRow_ActiveFlag != undefined)) {
                    DialogConfirmSave("GENL-002");
                    onPagingLastSel = true;
                    return 'stop';
                }
                else {
                    lastsel = null;
                    //enable New Button
                    $("#NewBtnId").removeClass('add-new-button-disable');
                    $("#NewBtnId").removeAttr("disabled");
                }
            }
        },

        // load all States into jqGrid dropdown 
        beforeProcessing: function (response) {
            var $self = $(this),
            options = response.colModelOptions, StateIdentifier;
            if (options != null) {
                for (StateIdentifier in options) {
                    if (options.hasOwnProperty(StateIdentifier)) {
                        $("#CountyGrid").jqGrid("setColProp", StateIdentifier, options[StateIdentifier]);
                    }
                }
            }
        },

        // Grid column header alignment to the left diable new button for general users
        loadComplete: function () {           
            $("#CountyGrid").jqGrid("setLabel", "Active", "", { "text-align": "left" })
            $("#CountyGrid").jqGrid("setLabel", "StateIdentifier", "", { "text-align": "left" })
            $("#CountyGrid").jqGrid("setLabel", "CountyText", "", { "text-align": "left" })
            $("#CountyGrid").jqGrid("setLabel", "CountyNumber", "", { "text-align": "left" })
        },

        pager: jQuery('#CountyPager'),
        rowNum: jqGridRowCount,
        rowList: GridRowList,
        viewrecords: true,
        emptyrecords: 'No records to display',
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            Id: "0"
        },
        multiselect: false,
        autowidth: true,
        height: 560,
        hidegrid: false,
    }).navGrid('#CountyPager', {
        edit: false, add: false, del: false, search: false, refresh: false, reload: false, restoreAfterSelect: false
    })
});

我的控制器代码:

public JsonResult GetCountyResult(string sidx, string sord, int page, int rows, bool getAllRecords = false)
{
    objCountyViewModel = new CountyViewModel();
    int totalRecords = 0;
    if (Session["CountyList"] != null && Session["CountyList"] is List<CountyModel>)
    {
        objCountyViewModel.CountyModelList = (List<CountyModel>)Session["CountyList"];
        if (objCountyViewModel.CountyModelList != null)
        {
            Session["CountyList"] = objCountyViewModel.SortCounty(sidx, sord);
            totalRecords = objCountyViewModel.CountyModelList.Count();
        }
    }
    var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
    rows = getAllRecords ? totalRecords : rows;

    var jsonData = new
    {
        colModelOptions = new
        {
            StateIdentifier = new
            {
                formatter = "select",
                edittype = "select",
                editoptions = new
                {
                    value = objCountyViewModel.GetStateDropdownList()
                }
            }
        },
        total = totalPages,
        page,
        records = totalRecords,
        rows = objCountyViewModel.GetCountyPageList(page, rows)
    };
    return Json(jsonData, JsonRequestBehavior.AllowGet);
}

0 个答案:

没有答案