电话号码:数据表中失去的排序列和顺序AJAX刷新后 [英] p:datatable loses sort column and order after ajax refresh

查看:183
本文介绍了电话号码:数据表中失去的排序列和顺序AJAX刷新后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,使我的数据表通过Ajax请求刷新的按钮。事情是这样的:

I have a button on a page that causes my data table to refresh via an AJAX request. Something like this:

<h:form id="datatable">
<p:dataTable/>
</h:form>
<p:commandButton update=":datatable">

这是一切优秀的花花公子,只是当表刷新它恢复到未排序的东西,同时还显示出,它的基础上,previous值排序。换句话说,首标是仍突出和箭头仍然指向在排序的方向,但实际上没有正在执行的排序。显然,这是不理想的。

This is all fine an dandy except that when the table is refreshed it reverts to not sorting anything while still showing that it's sorting based on the previous value. In other words, the header is still highlighted and the arrow is still pointing in the sort direction but no sort is actually being performed. Obviously this isn't ideal.

在理想情况下,我想的成分,以保持它的视图状态排序顺序,然后在AJAX请求期间提交适当的参数(这样排序是正确定义)。我缺少一个参数什么的?没有任何人有这个问题?

Ideally I'd like the component to keep it's sort order in the view state and then submit the proper parameters during the AJAX request (so that the sort is correctly defined). Am I missing a parameter or something? Does anyone else have this issue?

从我可以告诉当表期待一种回到它张贴下列选项:

From what I can tell when the table is expecting a sort back it posts the following options:

<componentID>_sortDir
<componentID>_sortKey
<componentID>_sorting
<componentID>_updateBody

在我刷新窗体不会发生这种情况。它也不会,如果我只是刷新表发生(以为我能解决的事情直接更新组件)。有没有办法让表正确刷新?

When I refresh the form this doesn't happen. It also doesn't happen if I just refresh the table (thought I could work around things by updating the component directly). Is there a way to get the table to refresh correctly?

推荐答案

我写了一个扩展@ truemmer的解决方案。他的恢复排序顺序返回到默认,在矿山将恢复到用户选择的previous排序。

I wrote an extension to @truemmer's solution. His reverts the sorting order back to the default, where as mine will reverts to the previous sort the user selected.

function postAjaxSortTable(datatable)
{
    var selectedColumn = datatable.jq.find('.ui-state-active');
    if(selectedColumn.length <= 0)
    {
        return;
    }
    var sortorder = "ASCENDING";
    if(selectedColumn.find('.ui-icon-triangle-1-s').length > 0)
    {
        sortorder = "DESCENDING";
    }
    datatable.sort(selectedColumn, sortorder);
}

更新相同的表truemmer的作品是这样的:

Updating the same table as truemmer's works like this:

<p:commandButton value="refresh" action="#{tableController.refreshPrices}" update="myTable" oncomplete="postAjaxSortTable(myTableWidget)" />

编辑:Primefaces 4.0 MultiSort支持

Primefaces 4.0 MultiSort support

function postAjaxSortTable(datatable) {
    var selectedColumn = undefined;

    // multisort support
    if(datatable && datatable.cfg.multiSort) {
        if(datatable.sortMeta.length > 0) {
            var lastSort = datatable.sortMeta[datatable.sortMeta.length-1];
            selectedColumn = $(document.getElementById(lastSort.col));
        }
    } else {
        selectedColumn = datatable.jq.find('.ui-state-active');
    }

    // no sorting selected -> quit
    if(!selectedColumn || selectedColumn.length <= 0) {
        return;
    }

    var sortorder = selectedColumn.data('sortorder')||"DESCENDING";
    datatable.sort(selectedColumn, sortorder, datatable.cfg.multiSort);
}

这篇关于电话号码:数据表中失去的排序列和顺序AJAX刷新后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆