gpt4 book ai didi

jquery - 如何在 jqGrid 中设置行操作

转载 作者:行者123 更新时间:2023-12-01 05:05:51 26 4
gpt4 key购买 nike

使用 jquery 的 jqGrid 插件,我将其设置为进行排序、分页和搜索。现在我需要做的是在每一行中添加链接以重定向到不同的页面,例如根据该行的 id 进行编辑(我不想使用 jqGrid 编辑。)如何在网格单元格中创建链接? p>

最佳答案

能够弄清楚,请注意 gridComplete 事件:

jQuery(document).ready(function () {

jQuery("#list").jqGrid({
url: '/admin/campus/getnearbybusinesses',
datatype: "json",
colNames: ['Id', 'Name', 'Location', 'Verification', ''],
rowNum: 15,
/*rowList: [20, 40, 60],*/
pager: '#pager',
sortname: "Name",
sortorder: "asc",
viewrecords: true,
caption: "Businesses",
width: 930,
height: 470,

colModel: [
{ name: 'Id', hidden: true, sortable: false, search: false, width: 0 },
{ name: 'Name', index: 'Name', search: true, searchoptions: { sopt: ['cn']} },
{ name: 'Location', index: 'Location', search: false },
{ name: 'VerificationCode', index: 'VerificationCode', sortable: false, search: false, width: 40 },
{ name: 'action', index: 'action', sortable: false, search: false, width: 160 }
],

jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id",
userdata: 'rows'
},

gridComplete: function () {
var grid = jQuery("#list");
var ids = grid.jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var rowData = $("#list").getGridParam('userData')[ids[i] - 1];
var id = rowData.Id;
var viewButton = "<a href='/business/home/" + id + "/index' class='button'>View</a>&nbsp;&nbsp;";
var upgradeDowngradeButton = "<a href='/admin/business/" + id + "/index' class='button'>Upgrade/Downgrade</a>&nbsp;&nbsp;";
var deleteButton = "<a href='javascript:void(0)' onclick='doDelete(" + id + ")' class='button'>Delete</a>";
grid.jqGrid('setRowData', ids[i], { action: viewButton + upgradeDowngradeButton + deleteButton });
}
}
});

jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });

});

关于jquery - 如何在 jqGrid 中设置行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5971523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com