jqGrid的用法詳解

jqGrid是一種用來顯示網格數據的jQuery插件,通過使用jqGrid可以輕鬆實現前端頁面與後臺數據的ajax異步通信。文檔比較全面,其官方網址爲:http://www.trirand.com。效果如下圖所示:

wKiom1RRksqCfZHfAAe6DqFzWDk381.jpg

js代碼如下:

function initData(p) {
    $("#customerMainList").jqGrid({
        url: "",
        datatype: "local",
        colNames: ['編號', '客戶姓名(跟進)', '類型', '添加人', '分配給', '期望區域', '期望小區', '期望面積', '戶型', '期望裝修', '期望樓層', '期望總價', '狀態', '添加時間', '操作'],
        colModel: [
   		{ name: 'Id', index: 'Id', formatter: tranCustId, width: 70, align: "center" },
   		{ name: 'CustName', index: 'CustName', formatter: transName, width: 98, align: "center" },
   		{ name: 'BusinessType', index: 'BusinessType', width: 60, align: "center" },
   		{ name: 'CreateUserName', index: 'CreateUserName', width: 55, align: "center" },
   		{ name: 'ExeUserName', index: 'ExeUserName', width: 65, align: "center" },
   		{ name: 'ExpArea', index: 'ExpArea', width: 70, align: "center" },
   		{ name: 'ExpSeqv', index: 'ExpSeqv', width: 77, align: "center" },
   		{ name: 'ExpAcre', index: 'ExpAcre', width: 70, align: "center" },
   		{ name: 'ExpShi', index: 'ExpShi', formatter: transHuX, width: 67, align: "center" },
   		{ name: 'ExpZhuangX', index: 'ExpZhuangX', width: 60, align: "center" },
   		{ name: 'ExpFloor', index: 'ExpFloor', width: 59, align: "center" },
   		{ name: 'ExpPriceT', index: 'ExpPriceT', formatter: transExpPrice, width: 59, align: "center" },
        { name: 'S2', index: 'S2', formatter: custStates, width: 53, align: "center" },
   		{ name: 'CreateDate', index: 'CreateDate', formatter: transDate, width: 65, align: "center" },
   		{ name: 'id', index: 'id', formatter: transOp, width: 74, align: "center" }

   	],
        rowNum: 20,
        hoverrows: true,
        rowList: [15, 20, 25, 30, 35, 40, 45, 50],
        pager: '#pager2',
        sortname: 'Id',
        viewrecords: true,
        sortorder: "desc",
        height: "100%", emptyrecords: "沒有記錄", forceFit: true, gridview: true, pginput: true,
        prmNames: { page: "page", rows: "rows", sort: "sidx", order: "sord", search: "_search", nd: "nd", npage: null },
        viewsortcols: [false, 'vertical', true],
        onSelectRow: function (rowid, status) {
            ShowCustomerDetail(rowid, true);
        }
    });
    $("#customerMainList").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false, refresh: false, search: false });
    refreshData(p);
}

設置jqGrid顯示的列,分頁等基本信息,需要注意的是colNames和colModel對應的字段信息要一致,onSelectRow事件表示的是行選中事件,在這裏可以在選中行的同時彈出該記錄的詳情頁面。

function refreshData(p) {
    cust_p = p;
    $("input[type='button']").attr("disabled", true);
    var where = calcWhere();
    $("#customerMainList").jqGrid("setGridParam", {
        url: "xxxx.aspx" + where,    //設置表格的url
        datatype: "json", page: p
    }).trigger("reloadGrid");
    $("input[type='button']").attr("disabled", false);
    $(".ui-jqgrid-bdiv div").css("position", "");
}

設置jqGrid請求的url,參數等信息,返回的是json格式。.net論壇:http://bbs.netluntan.com,羣:121058751


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章