如何在 jqGrid 中设置行操作

发布于 2024-11-06 19:29:52 字数 121 浏览 0 评论 0原文

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

Using jquery's jqGrid plugin, I have it setup to do sorting, paging, and searching. Now what I need to do is add links in each row to redirect to different pages like edit for example based on that row's id (I don't want to use the jqGrid edit.) How would I create links within grid cells?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-11-13 19:29:52

能够弄清楚,请注意 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>  ";
                    var upgradeDowngradeButton = "<a href='/admin/business/" + id + "/index' class='button'>Upgrade/Downgrade</a>  ";
                    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 });

    });

Was able to figure it out, note the gridComplete event:

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>  ";
                    var upgradeDowngradeButton = "<a href='/admin/business/" + id + "/index' class='button'>Upgrade/Downgrade</a>  ";
                    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 });

    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文