2

我从以下网址下载了这个 jqgrid 示例:http ://tpeczek.codeplex.com/releases/view/61796

我更新了“基础”网格,并且每一行都显示了一个编辑按钮。单击此按钮并传入产品 ID 时,我想转到另一个编辑页面。但是没有回发?另外,我怎样才能让 productID 显示正确的值,因为现在它显示的是产品名称(ev 向左移动)

网格

<script type="text/javascript">
        $(document).ready(function () {
            $('#jqgProducts').jqGrid({
                //url from wich data should be requested
                url: '@Url.Action("Products")',
                //type of data
                datatype: 'json',
                //url access method type
                mtype: 'POST',
                //columns names
                colNames: ['Actions', 'ProductID', 'ProductName', 'SupplierID', 'CategoryID', 'QuantityPerUnit', 'UnitPrice', 'UnitsInStock'],
                //columns model
                colModel: [
                     { name: 'act', index: 'act', width: 55, align: 'center', sortable: false, formatter: 'actions' },
                     { name: 'ProductID', index: 'ProductID', align: 'left' },
                            { name: 'ProductName', index: 'ProductName', align: 'left' },
                            { name: 'SupplierID', index: 'SupplierID', align: 'left' },
                            { name: 'CategoryID', index: 'CategoryID', align: 'left' },
                            { name: 'QuantityPerUnit', index: 'QuantityPerUnit', align: 'left' },
                            { name: 'UnitPrice', index: 'UnitPrice', align: 'left' },
                            { name: 'UnitsInStock', index: 'UnitsInStock', align: 'left' }
                          ],
                //pager for grid
                pager: $('#jqgpProducts'),
                //number of rows per page
                rowNum: 10,
                //initial sorting column
                sortname: 'ProductID',
                //initial sorting direction
                sortorder: 'asc',
                //we want to display total records count
                viewrecords: true,
                //grid height
                height: '100%',
                editurl: '/Edit'
            });

            $('#jqgProducts').navGrid('#pagerComponents', { edit: false }).
         navButtonAdd('#pagerComponents', {
             caption: "fdsfsdf",
             title: "Edit Component",
             buttonicon: "ui-icon-pencil",
             onClickButton: function () {
                 var id = jQuery("#listComponents").getGridParam('selrow');
                 if (id) {
                     var data = jQuery("#listComponents").getRowData(id);
                     window.location = '/Edit/' + data.COMPONENTID;
                 }
                 else {
                     alert("Please select a row to edit.");
                 }
             }
         });





        });


    </script>
4

1 回答 1

0

因此,对于您问题的第一部分,如果您想通过单击该行中的编辑按钮重定向到特定的 url,那么您需要使用操作格式化程序指定一些内容。我告诉你怎么做

http://www.ok-soft-gmbh.com/jqGrid/ActionButtons41WithoutMultiedit.htm

在此处查看此示例,我们提供带有操作格式化程序的 deloptions,您可以像这样指定 url 进行编辑

editOptions:{url: '@Url.Action("EditAction")', restoreAfterError: false}

默认情况下,可编辑的行的数据将转到服务器,您需要指定可编辑的:真实的列,例如您希望像这样可编辑的列

{ 名称:'ProductName',索引:'ProductName',对齐:'left',可编辑:true },

因此,现在如果您单击操作格式化程序的编辑,它将带您到带有可编辑列数据的“EditAction”,您可以在那里使用它。

对于第二部分,我觉得一切都很好。您能否检查从服务器获取的数据,您正在加载到 jqgrid 的数据按字母顺序与 jqgrid 中的列名相同,否则请检查提琴手或开发人员工具中的响应。

于 2012-07-31T15:54:31.767 回答