c# - jqGrid subGridRowExpanded 功能无法正常工作

标签 c# jquery asp.net-mvc jqgrid jqgrid-asp.net

我是 jQgrid 的初学者,最近几天我尝试学习 jQgrid 并创建一个示例

Mvc 应用程序。请参阅 jQgrid 网站。 http://www.trirand.com/blog/jqgrid/jqgrid.html

我尝试在 jQGrid 中创建一个网格作为子网格。我想要所有的添加、编辑、删除功能

子网格是可能的。

当我在 jQgrid 中展开一行时遇到问题,父行未显示

折叠图标。请看下面我的图片。

enter image description here

请看红框。它没有显示减号图标。请参阅下面我的代码。

  <table id="listsg11">
</table>
<div id="pagersg11">
</div>
<script type="text/javascript">
    jQuery("#listsg11").jqGrid({
        url: '/Home/DynamicGridData/',
        datatype: "json",
        mtype: 'POST',
        height: 190,
        width: 600,
        colNames: ['Id', 'Votes', 'Title'],
        colModel:
        [
            { name: 'Id', index: 'Id', width: 40, align: 'left' },
            { name: 'Votes', index: 'Votes', width: 40, align: 'left' },
            { name: 'Title', index: 'Title', width: 400, align: 'left' }
        ],
        rowNum: 8,
        rowList: [8, 10, 20, 30],
        pager: '#pagersg11',
        sortname: 'id',
        viewrecords: true,
        sortorder: "desc",
        multiselect: false,
        subGrid: true,
        caption: "Grid as Subgrid"
        ,
        subGridRowExpanded: function (subgrid_id, row_id) {
            // we pass two parameters 
            // subgrid_id is a id of the div tag created whitin a table data 
            // the id of this elemenet is a combination of the "sg_" + id of the row 
            // the row_id is the id of the row 
            // If we wan to pass additinal parameters to the url we can use 
            // a method getRowData(row_id) - which returns associative array in type name-value 
            // here we can easy construct the flowing
            var subgrid_table_id, pager_id;
            subgrid_table_id = subgrid_id + "_t";
            pager_id = "p_" + subgrid_table_id;
            $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
            jQuery("#" + subgrid_table_id).jqGrid({
                url: "/Home/DynamicGridData1/",
                datatype: "json",
                mtype: 'POST',
                colNames: ['Id', 'Votes', 'Title'],
                colModel:
                [
                    { name: 'Id', index: 'Id', width: 40, align: 'left' },
                    { name: 'Votes', index: 'Votes', width: 40, align: 'left' },
                    { name: 'Title', index: 'Title', width: 400, align: 'left' }
                ],
                rowNum: 20,
                rowList: [8, 10, 20, 30],
                pager: pager_id,
                sortname: 'Id',
                sortorder: "asc",
                height: 180,
                width: 500,
            });
            jQuery("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id, { edit: true, add: true, del: true })
        }
        //,
        //            subGridRowColapsed: function (subgrid_id, row_id) {
        //                alert(row_id);
        //                // this function is called before removing the data 
        //                //var subgrid_table_id; 
        //                //subgrid_table_id = subgrid_id+"_t"; 
        //                //jQuery("#"+subgrid_table_id).remove();
        //            }
    });
    jQuery("#listsg11").jqGrid('navGrid', '#pagersg11', { add: true, edit: true, del: true });

</script>

请帮忙。

最佳答案

为什么你不尝试将 javascript 放入

$(function(){
//here go the script
});

因为原因之一是jqgrid还没有正确下载。

所以试试这个!

祝你好运!

关于c# - jqGrid subGridRowExpanded 功能无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14117866/

相关文章:

c# - 编写扩展方法来调用控件的更好方法?

javascript - 将嵌套列表放入文本区域不会关闭所有 <ul>

javascript - JQuery Ajax 控制流程

c# - 使用 ASP.NET MVC4 将 View 中的 DropDownList 绑定(bind)到表中的列

c# - 如何使用来自不同项目的模型类通过反射提供程序创建 WCF 数据服务 OData?

c# - 在 LINQ 中使用 “OfType”

c# - EF Core 3.1 在定义实体之间的主键关系时创建名称为 '1' 的重复列

javascript - Uncaught ReferenceError : error is not defined in Ajax Callback

asp.net - MVC5 ApplicationUser 自定义属性

c# - 将登录页面设置为asp.net mvc 5中的默认页面