1

这是我的示例项目的 jQuery 代码,用于从应用程序端获取详细信息以显示在由 jsGrid 构建的网格的前面。

$("#part_table").jsGrid({
            height: "auto",
            width: "100%",
            autoload: true,
            editing: true,
            sorting: true,
            paging: true,
            pageSize: 10,
            inserting: true,
            loadIndication: false,
            filtering: true,
            headerRowClass: 'table-green-header',
            controller: {
                loadData: function (filter) {
                    function.....
                },
                updateItem: function (item) {

                    function.....

                }
            },
            fields: [
                { name: "Id", type: "number", visible: false },
                {
                    name: "CatalogueId", type: "select", **items**: catalouges, valueField: "Id", textField: "CatalougeName", selectedIndex : -1 , title: "Catalouge Name", align: "center"
                },

                { name: "DistributorPrice", type: "number", title: "Distributor Price", align: "center", filtering: false, sorting: false },
                { name: "IsActive", type: "checkbox", filtering: false, sorting: false },
                { type: "control" }


            ],
            rowClick: function (args) {
                return false;
            },
        });

谁能说如何通过 AJAX 调用应用程序端来获取要字段的项目列表?

谢谢

4

3 回答 3

3

提前加载项目,然后在网格字段配置中使用结果,例如:

$.ajax({
    type: "GET",
    url: "/countries/"
}).done(function(countries) {

    countries.unshift({ id: "0", name: "" });

    $("#jsGrid").jsGrid({
        ...,
        fields: [
            ...
            { name: "country_id", title: "Country", type: "select", width: 100, items: countries, valueField: "id", textField: "name" }
        ]
    });

});

您可以在jsgrid 示例项目中找到示例

于 2016-08-15T17:42:13.557 回答
1

您可以在网格启动之前同时执行多个请求

$.when(

    $.get("/api/v1/clients", function(clients) {
        db.clients = clients;
    }),

    $.get("/api/v1/owners", function(owners) {
        db.owners = owners;
    })

).then(function() {

    $("#jsGrid").jsGrid({
        ...,

        fields: [
            { name: "client", title: "Client", type: "select", items: db.clients, valueField: "name", textField: "name" },
            { name: "owner", title: "Owner", type: "select", items: db.owners, valueField: "short_name", textField: "short_name" },

        ]
    });
});
于 2020-11-19T22:54:09.387 回答
0

您在控制器的 loadData 中编写 ajax 调用.. 类似于:

controller: {
                loadData: function(filter) {
                    return $.ajax({
                        type: "GET",
                        url: "/api/data",
                        data: filter,
                        dataType: "json"
                    });
}                    
}

进一步参考https://github.com/tabalinas/jsgrid-webapi

于 2016-08-15T07:47:03.200 回答