如何使用jsGrid在字段中获得项目的下拉列表
How to get items to dropdown list in a field using jsGrid?
这是我的示例项目的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调用到应用程序端来获得项目列表字段?
谢谢
提前加载项,然后在网格字段配置中使用结果,例如:
$.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示例项目
可以在网格启动前同时执行多个请求
$.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" },
]
});
});
在控制器的loadData中编写ajax调用。例如:
controller: {
loadData: function(filter) {
return $.ajax({
type: "GET",
url: "/api/data",
data: filter,
dataType: "json"
});
}
}
进一步参考https://github.com/tabalinas/jsgrid-webapi
相关文章:
- 如何在页面加载后禁用下拉列表框项目的选择
- 如何使用jquery将所选项目从一个下拉组列表(optgroup)移动到另一个下拉列表(optgroup)
- 如何在角度js的自动完成下拉列表中对项目列表(按字母顺序)进行排序
- 从下拉列表中获取所选项目,并将其保存到php变量中
- 更改localStorage和下拉列表中的项目值
- 根据下拉列表中选择的项目隐藏所有元素
- 仅在单击下拉列表中的项目时显示列表框
- 双击下拉列表中的选定项目
- 我正试图获得一个带有复选框的多选下拉列表,在填充项目和获得所有选中的工作时遇到了一些问题
- 在复选框取消选中事件中从HTML下拉列表中删除项目
- AngularJS下拉列表在选择项目后丢失内容
- 如何将所选项目从角度 UI 下拉列表发送回角度控制器
- 从下拉列表中的数组中选取某个项目,然后将其显示为第一项并按字母顺序显示
- 检查是否未从下拉列表中选择项目
- 通过下拉列表框上的 appendChild 方法添加的项目不会显示在 IE8 下
- 使用类似 Greasemonkey 的脚本自动选择每页的项目(下拉列表)
- 表单下拉列表(微调器)并尝试将值更改为所选项目值
- 使用 javascript 将项目添加到下拉列表中并保留在回发中
- 所选项目-下拉列表- SQL
- 我可以添加项目下拉列表只有当我点击它(onclick事件)