【问题标题】:KendoUI Grid parameters sending to a symfony2 appKendoUI Grid 参数发送到 symfony2 应用程序
【发布时间】:2014-03-06 23:02:56
【问题描述】:

我正在使用带有服务器分页的 KendoUI 网格,我也在服务器端使用 symfony2,我已经创建了处理请求的路由:

_callsList:
    pattern:   /callsList/{id_client}/{take}/{skip}/{page}/{pageSize}
    defaults:  { _controller: StoreBundle:Voip:callsList, take: 20, skip: 0, page: 1, pageSize: 20 }

这是我对网格的定义:

$("#grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: "{{url('_callsList', {'id_client': 3, 'take': 20, 'skip': 0, 'page': 1, 'pageSize': 20})}}"
                            },
                            schema: {
                                model: {
                                    fields: {
                                        callerId: { type: "string" },
                                        calledNumber: { type: "string" },
                                        callStart: { type: "string" },
                                        duration: { type: "string" }
                                    }
                                }
                            },
                            pageSize: 20,
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true,
                            schema: {
                                total : "total",
                                data: "result"
                            }
                        },
                        height: 430,
                        scrollable: true,
                        sortable: true,
                        pageable: {
                            input: true,
                            numeric: false
                        },
                        columns: [
                            { field: "callerId", title: "Numero de Salida", width: "130px" },
                            { field: "calledNumber", title: "Numero de Destino", width: "180px" },
                            { field: "callStart", title: "Fecha", width: "100px" },
                            { field: "duration", title: "Duracion (segundos)", width: "80px" }
                        ]
                    });

网格加载正常,但是当我点击第二页时,发送到服务器的 URL 是这样的:

http://mydomain.com/app_dev.php/callsList/3/20/0/1/20?take=20&skip=20&page=2&pageSize=20

Grid 无法获取第二页,一直拉取前 20 个结果。正确的 URL 应该是这样的:

http://mydomain.com/app_dev.php/callsList/3/20/20/2/20

正如我在路由文件上设置的那样。

知道如何解决这个问题吗???

谢谢!

【问题讨论】:

    标签: php symfony kendo-grid


    【解决方案1】:

    根据这个库的工作原理,我建议在 ControllerAction 本身而不是在 url 参数中解析这些选项。

    //routing
    _callsList:
        pattern:   /callsList/{id_client}/
        defaults:  { _controller: StoreBundle:Voip:callsList }
    

    然后你的控制器动作

    public function callsListAction(Request $request, Client $client)
    {
        $defaults = array(
            "take" => 20,
            "skip" => 0,
            "page" => 1,
            "pageSize" => 20
        );
        $options = array_merge($defaults, $request->query->all());
    
        //This should give you your defaults merged with any passed params in $options
        // So /callsList?page=2 will give you:
        // array( "take" => 20,
        //  "skip" => 0,
        //  "page" => 2,
        //  "pageSize" => 20
        // )
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 2018-09-02
      相关资源
      最近更新 更多