簡體   English   中英

jqgrid 如何根據選定的行數據禁用工具欄

[英]jqgrid how to disable toolbar base on selected row data

I'am working now on a project in c# asp.net web form and i require to load data from database using jqgrid i able to load the expected result but how can i disable the toolbar below the (edit delete) base on selected row if the shield列是 1

在此處輸入圖像描述

這是我加載數據的代碼

<script>
        $(document).ready(function () {

            loadAuditlogsGrid();
        });
        function loadAuditlogsGrid() {

            $('#Auditgrid').jqGrid("GridUnload");
            getlist(function (data) { loadAuditLogs(data); });
        }

        function getlist(callback) {

            $.ajax({
                async: true,
                type: 'POST',
                contentType: 'application/json',
                url: 'WebForm1.aspx/getlist',

                dataType: 'json',
                success: function (data) {
                    timelog = data.d;

                    if (typeof callback != 'undefined')
                        callback(timelog);
                },
                error: function (xhr, status, error) {
                    console.log(xhr, status, error);
                    hideLoadingGif();
                }
            });


        }

        function loadAuditLogs(Auditlog) {

            var lastsel;
            var startpage = 1;
            $('#Auditgrid').jqGrid({
                datatype: 'local',
                data: Auditlog,
                editurl: 'clientArray',
                colNames: ['NAME', 'Shield'],

                colModel: [
                         { name: 'name', index: 'name', editable: 'true', align: 'center', width: '190', resizable: false },
                         { name: 'shield', index: 'shield', editable: 'true', align: 'center', width: '175', resizable: false },




                ],
                pager: '#Auditgridpager',
                viewrecords: true,
                forceFit: true,
                shrinkToFit: false,
                width: '1150',
                emptyrecords: "No Record/s found",
                loadtext: "Loading",
                rowList: [5, 10, 20, 50],
                height: 'auto',
                caption: 'Audit Logs'

            });

            $('#Auditgrid').jqGrid('navGrid', '#Auditgridpager', {
                edit: true,
                save: false,
                add: true,
                cancel: true,
                del: true,
                search: false,
                refresh: false
            });
            $('#Auditgrid').jqGrid('inlineNav', '#Auditgridpager', {
                add: true,
                edit: true,
                save: true,
                cancel: true,
                restoreAfterSelect: false
            });
        }
    </script>

對不起,我的英語不好。

我已經通過添加 oncellselect 解決了我的問題,這是我的最終代碼

  <script>
        $(document).ready(function () {

            loadAuditlogsGrid();
        });
        function loadAuditlogsGrid() {

            $('#Auditgrid').jqGrid("GridUnload");
            getlist(function (data) { loadAuditLogs(data); });
        }

        function getlist(callback) {

            $.ajax({
                async: true,
                type: 'POST',
                contentType: 'application/json',
                url: 'WebForm1.aspx/getlist',

                dataType: 'json',
                success: function (data) {
                    timelog = data.d;

                    if (typeof callback != 'undefined')
                        callback(timelog);
                },
                error: function (xhr, status, error) {
                    console.log(xhr, status, error);
                    hideLoadingGif();
                }
            });


        }

        function loadAuditLogs(Auditlog) {

            var lastsel;
            var startpage = 1;
            $('#Auditgrid').jqGrid({
                datatype: 'local',
                data: Auditlog,
                editurl: 'clientArray',
                colNames: ['NAME', 'Shield'],

                colModel: [
                         { name: 'name', index: 'name', editable: 'true', align: 'center', width: '190', resizable: false },
                         { name: 'shield', index: 'shield', editable: 'true', align: 'center', width: '175', resizable: false },




                ],
                pager: '#Auditgridpager',
                viewrecords: true,
                forceFit: true,
                shrinkToFit: false,
                width: '1150',
                emptyrecords: "No Record/s found",
                loadtext: "Loading",
                rowList: [5, 10, 20, 50],
                height: 'auto',
                caption: 'Audit Logs',
                onCellSelect: function (rowid) {

                    var gridId = $.jgrid.jqID(this.id);
                    if ($(this).jqGrid('getCell', rowid, 'shield') === '1') {
                        // disable the "Edit" and "Delete" buttons of the navigator
                        $("#edit_" + gridId).addClass('ui-state-disabled');
                        $("#del_" + gridId).addClass('ui-state-disabled');
                    } else {
                        // enable the "Edit" and "Delete" buttons of the navigator
                        $("#edit_" + gridId).removeClass('ui-state-disabled');
                        $("#del_" + gridId).removeClass('ui-state-disabled');
                    }

                }


            });

            $('#Auditgrid').jqGrid('navGrid', '#Auditgridpager', {
                edit: true,
                save: false,
                add: true,
                cancel: true,
                del: true,
                search: false,
                refresh: false
            });
            //$('#Auditgrid').jqGrid('inlineNav', '#Auditgridpager', {
            //    add: true,
            //    edit: true,
            //    save: true,
            //    cancel: true,
            //    restoreAfterSelect: false
            //});

        }
    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM