Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery jqGrid中未格式化的行数据_Jquery_Jqgrid - Fatal编程技术网

Jquery jqGrid中未格式化的行数据

Jquery jqGrid中未格式化的行数据,jquery,jqgrid,Jquery,Jqgrid,在Oleg中,描述了如何从jqGrid的行id中检索行数据 在我的代码中,我希望显示有关子网格行中的行的更多数据展开: standardGrid.subGridRowExpanded = function (subgridId, rowId) { var dataFromTheRow = jQuery('#CompanyGrid').jqGrid('getRowData', rowId); var html = '<span style="padding-left:80px

在Oleg中,描述了如何从jqGrid的行id中检索行数据

在我的代码中,我希望显示有关子网格行中的行的更多数据展开:

standardGrid.subGridRowExpanded = function (subgridId, rowId) {
    var dataFromTheRow = jQuery('#CompanyGrid').jqGrid('getRowData', rowId);
    var html = '<span style="padding-left:80px">' + dataFromTheRow.CompanyName + ' ' + 
        dataFromTheRow.StatusDesc + '</span>';
    $("#" + subgridId).html(html);
}

并将CompanyName行的colModel更改为

{ name: 'CompanyName', label: 'Company Name', search: true, formatter: CompanyLink, unformat: CompanyUnLink },
但是,unformat例程传递一个未使用锚点格式化的cellValue

我把不规则更改为

function CompanyUnLink(cellValue, options) {
    // weird, the unformat actually passes in the raw data, and not the decorated one
    return cellValue;
}
它是有效的。但在我看来,这似乎是错误的。有没有更好或正确的方法来做到这一点

下面是完整代码的一个小示例:

<table id="datalist"></table> 
<script type="text/javascript">
function CompanyLink(cellValue, options, rowdata, action) {
    return '<a href="CompanyProfile.aspx?CompanyId=' + rowdata.CompanyID + '">' + rowdata.CompanyName + '</a>';
}

function CompanyUnLink(cellValue, options, rowdata, action) {
    // weird, the unformat actually passes in the raw data, and not the decorated one
    return cellValue;
}


$("#datalist").jqGrid({
    datatype: 'local',
    colModel: [
                { name: 'CompanyID', label: 'Id', width: 30, align: "right" },
                { name: 'CompanyName', label: 'Company Name', search: true, formatter: CompanyLink },
            ],
    caption: "SubGrid Format Test",
    subGrid: true,
    subGridRowExpanded: function (subgridId, rowId) {
        var dataFromTheRow = $('#datalist').jqGrid('getRowData', rowId);
        var html = '<span style="padding-left:10px">' + dataFromTheRow.CompanyName + ' ' + dataFromTheRow.Info + '</span>';
        $("#" + subgridId).html(html);
    }
});

var mydata = [
        { CompanyID: 1, CompanyName: "Company1", Info: "Info on Company 1" },
        { CompanyID: 2, CompanyName: "Company2", Info: "Info on Company 2" },
        { CompanyID: 3, CompanyName: "Company3", Info: "Info on Company 3" },
        { CompanyID: 4, CompanyName: "Company4", Info: "Info on Company 4" },
    ];

for (var i = 0; i <= mydata.length; i++)
    $("#datalist").jqGrid('addRowData', i + 1, mydata[i]);

</script>

文本不再装饰。但unformat例程的cellValue是以未修饰的方式传递的,这让我觉得是错误的。

了解有关如何使用jqGrid的一些细节很重要。您是否按照Ajax填充主网格(因此您使用
数据类型:“json”
数据类型:“xml”
)?如果“是”,则是否使用
loadonce:true
选项?您是否使用
autoencode:true
选项?你想将子网格的数据与主网格的数据一起填充,并在用户点击子网格的“+”图标时显示详细信息吗?伙计,你太快了!我用Ajax填充主网格,数据类型:“json”,并且没有设置loadonce和autoencode(是否为false?)。subGridRowExpanded例程只是从关联行中提取数据,因此它不是标准意义上的“子网格”。(我想它是“在一起”的)看。也许它能满足你的需要?不需要将数据保存在隐藏列中。相反,可以将所有子栅格的所有数据保存为对象。可以在服务器响应的
userdata
部分中发布子网格信息,但可以在处理
之前在
userdata
中动态移动服务器响应的某些部分,如我在回答中所示。我用一个工作示例更新了我的问题。我认为我最初的帖子过于复杂了,因为它与ajax等无关。
{ name: 'CompanyName', label: 'Company Name', search: true, formatter: CompanyLink, unformat: CompanyUnLink },
function CompanyUnLink(cellValue, options) {
    // weird, the unformat actually passes in the raw data, and not the decorated one
    return cellValue;
}
<table id="datalist"></table> 
<script type="text/javascript">
function CompanyLink(cellValue, options, rowdata, action) {
    return '<a href="CompanyProfile.aspx?CompanyId=' + rowdata.CompanyID + '">' + rowdata.CompanyName + '</a>';
}

function CompanyUnLink(cellValue, options, rowdata, action) {
    // weird, the unformat actually passes in the raw data, and not the decorated one
    return cellValue;
}


$("#datalist").jqGrid({
    datatype: 'local',
    colModel: [
                { name: 'CompanyID', label: 'Id', width: 30, align: "right" },
                { name: 'CompanyName', label: 'Company Name', search: true, formatter: CompanyLink },
            ],
    caption: "SubGrid Format Test",
    subGrid: true,
    subGridRowExpanded: function (subgridId, rowId) {
        var dataFromTheRow = $('#datalist').jqGrid('getRowData', rowId);
        var html = '<span style="padding-left:10px">' + dataFromTheRow.CompanyName + ' ' + dataFromTheRow.Info + '</span>';
        $("#" + subgridId).html(html);
    }
});

var mydata = [
        { CompanyID: 1, CompanyName: "Company1", Info: "Info on Company 1" },
        { CompanyID: 2, CompanyName: "Company2", Info: "Info on Company 2" },
        { CompanyID: 3, CompanyName: "Company3", Info: "Info on Company 3" },
        { CompanyID: 4, CompanyName: "Company4", Info: "Info on Company 4" },
    ];

for (var i = 0; i <= mydata.length; i++)
    $("#datalist").jqGrid('addRowData', i + 1, mydata[i]);

</script>
    colModel: [
                { name: 'CompanyID', label: 'Id', width: 30, align: "right" },
                { name: 'CompanyName', label: 'Company Name', search: true, formatter: CompanyLink, unformat: CompanyUnLink },
            ],