【问题标题】:JQGrid Master Detail select/ MultiSelect on details grid not working详细信息网格上的 JQGrid 主详细信息选择/多选不起作用
【发布时间】:2010-11-07 17:59:04
【问题描述】:

我正在尝试 ASP.NET MVC 3(默认视图引擎)中的 Master Detail 场景。

我能够在http://www.trirand.com/blog/jqgrid/jqgrid.html 浏览以下代码并让主详细信息正常工作。问题是当我详细选择任何行时 第一行似乎被选中/未选中 点击链接查找所选id的返回,null,null,null,null,nul

你们中有人有过同样的经历吗?

如果您能指出我使用 JQGrid Master Details 工作的 ASP.NET MVC 示例,我们将不胜感激。

问候,

三月

编辑 - 代码

1- 查看页面

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/default.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Orders Available
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../../Content/ui.jqgrid.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/themes/redmond/jquery-ui-1.8.6.custom.css" rel="stylesheet"
        type="text/css" />
    <script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="../../Scripts/js/grid.locale-en.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="scriptContent" runat="server">
    <script type="text/javascript">
        jQuery(document).ready(function () {

            jQuery("#list10").jqGrid({
                url: '/order/list/',
                datatype: "json",
                mtype: 'post',
                colNames: ['PurchaseOrder', 'SalesOrder', 'OrderDate', 'Supplier', 'Status', "Details"],
                colModel: [
      { name: 'PurchaseOrder', index: 'PurchaseOrder', width: 100, align: 'left' },
                            { name: 'SalesOrder', index: 'SalesOrder', width: 100, align: 'left' },
                            { name: 'OrderDate', index: 'OrderDate', width: 75, align: 'left' },
                            { name: 'Supplier', index: 'Supplier', width: 150, align: 'left' },
                            { name: 'Status', index: 'Status', width: 50, align: 'left' },                          
                            { name: 'Details', index: 'Details', width: 50, align: 'left' }
    ],
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#pager10',
                sortname: 'id',
                viewrecords: true,
                sortorder: "desc",
                multiselect: false,
                caption: "Invoice Header",
                onSelectRow: function (ids) {
                    if (ids == null) {
                        ids = 0;
                        if (jQuery("#list10_d").jqGrid('getGridParam', 'records') > 0) {
                            jQuery("#list10_d").jqGrid('setGridParam', { url: "/order/detail/id=" + ids, page: 1 });
                            jQuery("#list10_d").jqGrid('setCaption', "Invoice Detail: " + ids)
                .trigger('reloadGrid');
                        }
                    } else {
                        jQuery("#list10_d").jqGrid('setGridParam', { url: "/order/detail/id=" + ids, page: 1 });
                        jQuery("#list10_d").jqGrid('setCaption', "Invoice Detail: " + ids)
            .trigger('reloadGrid');
                    }
                }
            });
            jQuery("#list10").jqGrid('navGrid', '#pager10', { add: false, edit: false, del: false });
            jQuery("#list10_d").jqGrid({
                height: 100,
                url: "/order/detail/",
                datatype: "json",
                colNames: ['Stock Number', 'Description', 'Available', 'Required'],
                colModel: [
        { name: 'PartNumber', index: 'StockNumber', width: 100, align: 'left' },
                            { name: 'Description', index: 'Description', width: 200, align: 'left' },
                            { name: 'Available', index: 'Available', width: 75, align: 'left' },
                            { name: 'Required', index: 'Required', width: 75, align: 'left' }
    ],
                rowNum: 5,
                rowList: [5, 10, 20],
                pager: '#pager10_d',
                sortname: 'item',
                viewrecords: true,
                sortorder: "asc",
                multiselect: true,
                caption: "Invoice Detail",
                beforeSelectRow: function(rowid, e) { return true; }

            }).navGrid('#pager10_d', { add: false, edit: false, del: false });
            jQuery("#ms1").click(function () {
                var s;
                s = jQuery("#list10_d").jqGrid('getGridParam', 'selarrrow');
                alert(s);
            });

        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="mainContent" runat="server">
    <div class="orderSelSum">
        <h3>
            Summary</h3>
        <p>
            Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots
            in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
            Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
            up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage,
            and going through the cites of the word in classical literature, discovered the
            undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
            Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC.
            This book is a treatise on the theory of ethics, very popular during the Renaissance.
            The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line
            in section 1.10.32</p>
    </div>
    <div id="orderMain">
        <table id="list10">
        </table>
        <div id="pager10">
        </div>
        <br />
        Invoice Detail
        <table id="list10_d">
        </table>
        <div id="pager10_d">
        </div>
        <a href="javascript:void(0)" id="ms1">Get Selected id's</a>
    </div>
</asp:Content>

2- JSON 结果

a) 对于主表

{"total":10,"page":1,"records":4,"rows":[{"id":"4cf2c07d-1f13-4add-8bf9-3e7bca441a69","cell":["NV32653-A","23434324","03/01/2010","MY Supplier","Ready for Use","\u003ca href=\u0027#\u0027\u003eDetails\u003c/a\u003e"]},{"id":"54f3b266-dd14-4137-ab76-6d4a1fd7fe7c","cell":["NV32653-A","23434324","03/01/2010","MY Supplier","Ready for Use","\u003ca href=\u0027#\u0027\u003eDetails\u003c/a\u003e"]},{"id":"ab63a5ae-1f00-43ed-a50e-d8fb60ff2df2","cell":["NV32653-A","23434324","03/01/2010","MY Supplier","Ready for Use","\u003ca href=\u0027#\u0027\u003eDetails\u003c/a\u003e"]},{"id":"484c0e05-80c6-4259-8a29-ca6be83037e4","cell":["NV32653-A","23434324","03/01/2010","MY Supplier","Ready for Use","\u003ca href=\u0027#\u0027\u003eDetails\u003c/a\u003e"]}]}

b) 细节

{"rows":[{"id":null,"cell":["PART A","Apple ","10","0"]},{"id":null,"cell":["PART B","Orange","12","0"]},{"id":null,"cell":["PART C","Banana","8","0"]},{"id":null,"cell":["PART D","Bread","10","0"]},{"id":null,"cell":["Part E","Jam","9","0"]}]}

一些图片

更新 1 发现 details json 包含 null 的 ID 字段。我会尽快纠正。

【问题讨论】:

  • 据我所见,人们更倾向于向欣赏并接受他们的答案的人提供帮助。
  • @PolishedTurd- 我明白你在说什么,我的一些问题并没有真正的答案,而有些问题是我自己回答的,我/不确定是否应该选择我的答案作为答案。
  • 是的,如果您自己的答案是合适的,请务必这样标记。

标签: jquery asp.net-mvc-2 jqgrid


【解决方案1】:

在 Master/Detail 场景中您必须考虑的唯一问题是在两个表中选择 id。重要的是要理解,jqGrid 使用从服务器返回的 id 作为网格的&lt;tr&gt; 元素的 id。因此,如果您对两个表使用相同的 id(重复),您将有冲突。

如果您在实施 Master/Detail 方案时仍然存在问题,您应该将问题附加到代码示例和一些测试数据中。可以将测试 JSON 数据保存到文本文件中以模拟服务器响应,因此不需要服务器代码。

【讨论】:

  • @Oleg- 感谢您的回复。我将在创建非专有数据以供显示后不久附加代码。
  • @Oleg- 我已经更新了帖子,提供了更多详细信息。因为您谈到了 Id,我在想,是否有可能所有当前为 null 的 id 都被视为相同并导致此问题。
  • @Oleg - 关于 Ids,你是对的。谢谢你。所有 Id 为空都会导致问题。
  • @TheMar:好的,我明白了。美好的!明天我会检查它并给你写更多。
  • @TheMar:很高兴来到这里!您可以只使用一个字符串作为 id,并为第一个 grig 使用一个前缀,为第二个 grig 使用另一个前缀。但是值 "id":null 看起来更像是服务器端的错误。如果应该很容易在服务器代码中查看(调试它)以找到错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-29
  • 1970-01-01
  • 1970-01-01
  • 2012-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多