显示来自两个连续相关数据库表的 jqGrid 数据

Show jqGrid data from two consecutive related database tables

我有这个场景:

一个数据库 table A,在 jqGrid 中显示其所有数据。 对于此 table 的一列,我有一个引用另一个数据库的外键 table B.
我已经设置了 AB 之间的关系,它在 jqGrid 中也完美显示。一切正常。

问题是:
我有其他列是引用 table B 的外键。但我需要的是显示 B 中引用其他 table C 的另一个外键。我已经能够证明 jqGrid 使用(糟糕地)formatter: 'select' 并从 PHP 创建自定义数组来欺骗解决方案。

问题是我可以看到数据,但由于执行不当,我无法过滤此列。

我使用 Twig 传递给 jqGrid,来自 PHP 的数组。 我需要创建两个辅助数组,一个包含 table A 的 ID 列表,另一个包含 table C 的值。我通过这种方式关联了两个 table。

这是我的代码:

// colModel
{name:'<%identificator%>', 
    index:'table_A_id', 
    jsonmap:'table_A_id',
    editable:true,
    editrules:{ edithidden:true, required:true },
    formoptions:{ elmsuffix:' (*)' }, 
    edittype: 'select', 
    stype:'select',
    formatter: 'select',
    editoptions:{
                    value:":<%repeat%>;<%table_A_id%>:<%table_C_value%><%/repeat%>"
                }

使用这段代码,我在每个单元格中都有正确的结果,但在 select 过滤列表中不正确。

正在恢复:我需要显示来自 table A 的 table C 中的值,但是两个 table 都没有关系,仅通过 table B.

有解决办法吗?

我用的是4.0.0版本的jqGrid,我没有使用loadonce属性。

最后,我认为解决方案非常特别:

我通过JSON把数据传给jqGrid的方式如下:

    // This is data from Table A(id, name, b_id)
    {
        "page":"1",
        "total":122,
        "records":3635,
        "rows":[
        {
            "id":1,
            "name":"example",
            "b_id":8
        },
        { 
            "id":2,
            "name":"example2",
            "b_id":19
        }]
    }

所以我无法关联 table A 和 C,但最终我在 PHP 中使用模型关系做到了:

// This is data from Table A(id, name, b_id) with relations
{
    "page":"1",
    "total":122,
    "records":3635,
    "rows":[
    {
        "id":1,
        "name":"example",
        "b_id":8,
        "relations":{
            "relation":{
                "id":200,"name":"Pepe", "id_c":22
            }
        }
    },
    { 
        "id":2,
        "name":"example2",
        "b_id":19,
        "relations":{
            "relation":{
                "id":356,"name":"Jose", "id_c":45
            }
        }
    }]
}

jqGrid 自动理解它,将正确的值放入 indexjsonmap :

    colModel:[ ...
, {
    name:'Title',
    index:'relation.id_c',
    jsonmap:'relations.relation.id_c',
    width: 40, editable:false
    stype:'select', formatter:'select',
    editoptions:{
        value:"ids_C_table:values_C_table"
    }
}
...]

有了这个实现,我得到了我需要的。单元格显示正确的数据和过滤器完美工作。

希望对大家有所帮助!