douzhui1972 2014-07-25 12:20
浏览 45
已采纳

在JQGrid列摘要中使用CakePHP从JSON编码响应访问密钥

I am sending json encoded results from my controller to my view and displaying data in jqgrid. The data is displaying fine. However, I added two integers to the response I am returning and I want to display them in the grid in one of the column's summary. This is what it looks like in the controller:

    $response->TotalNum = $total_items;
    $response->PercentNum = $percent_items;
    return json_encode($response);

How do I access those values in my grid? I would like to append them to the summary. Sort of like this, though I know this won't work:

{name:'itemcounts',index:'itemcounts', width: 50, sorttype:'int',summaryType:'sum', summaryTpl: 'Total<br>Count: {0}<br>Total Items: **$response['TotalNum']** (**$response['PercentNum']**%)', formatter:'number',formatoptions:{decimalPlaces: 0}},

Thank you!

  • 写回答

1条回答 默认 最新

  • duanchanguo7603 2014-07-25 15:33
    关注

    The easiest way to display summary row and fill it with the data prepared on the server is the usage of additional userdata property in the server response (its values mast be an object with properties defined as the column names) and options footerrow: true and userDataOnFooter. The old answer provides the corresponding example. If you prefer calculate the values for the footer row on the client side (which can be slowly) then you can calculate the summary using getCol and then call footerData explicitly inside of loadComplete callback. By the way the setting summaryType:'sum' will be used in case of groping of data (see here for example).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?