【问题标题】:Can jqgrid use with jQuery mobile?jqgrid 可以与 jQuery mobile 一起使用吗?
【发布时间】:2012-05-14 07:09:33
【问题描述】:

我想使用 ajax、jQuery mobile 和 spring mvc 显示来自数据库的数据。

示例:在表格中显示课程名称列表。

我现在使用 jqgrid 来显示数据,但是不使用数据还有其他选择吗?论坛里有很多,但大多使用php,但我使用spring mvc控制器。

请任何人帮助我..

【问题讨论】:

  • 您可以开始"accept" 回答您之前的问题。

标签: ajax jquery-mobile jqgrid


【解决方案1】:

不确定 jqgrid 是否适用于 jquery mobile,但对于普通的 Web 应用程序,您可以使用 addJSONData 方法并将 jsonReader 和 datatype 属性设置为函数。下面是一个示例:

function cfgWixGenApplicationsGrid() {
    var cond = null;
    $("#tblWixGenApplications").jqGrid({
        datatype: function (postdata) {
            var orderByExpr = "";
            if (postdata.sidx != "") {
                orderByExpr = postdata.sidx + " " + postdata.sord;
            }
            getPageList(cond, postdata.page, postdata.rows, orderByExpr, hSuccPageWixGenApplications, hError);
        },
        colNames: ["Id", "Title", "Name", "Version", "MainAssemblyName"
        ],
        colModel: [
            { name: "Id", index: "Id", width: 50, sorttype: "String", editable: false },

            { name: "Title", index: "Title", width: 50, sorttype: "String", editable: true },

            { name: "Name", index: "Name", width: 50, sorttype: "String", editable: true },

            {name: "Version", index: "Version", width: 50, sorttype: "String", editable: true },

            {name: "MainAssemblyName", index: "MainAssemblyName", width: 50, sorttype: "String", editable: true }
        ],
        multiselect: false,
        pager: "#divPagerWixGenApplications",
        viewrecords: true,
        jsonReader: { repeatitems: false, root: "rows", page: "page", records: "records", total: "total" },
        rowNum: 10,
        rowList: [10, 20, 30]
    });
}

getPageList 执行 ajax 调用,在我的例子中是 WCF 服务。我想你可以在这里调用MVC url。

hSuccPageWixGenApplications 函数像这样调用addJSONData:

function hSuccPageWixGenApplications(pageData) {
    var list = [];
    $.each(pageData.List, function (index, value) {
        if (!value.IsDeleted) {
            list.push(value);
        }
    });
    var grid = $("#tblWixGenApplications")[0];
    var pData = new Object();
    var recCount = pageData.RecordCount == null ? 1000 : pageData.RecordCount;
    pData.page = pageData.PageNo;
    pData.records = recCount;
    pData.rows = list;
    pData.total = recCount / pageData.PageSize;
    grid.addJSONData(pData);
};

【讨论】:

  • 但我需要做一个移动应用程序..这就是我使用 jquerymobile 的原因..我读到一些他们说 jqgrid 可以在移动设备中使用,但大多数示例使用 php..
猜你喜欢
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多