Flexigrid:选择行以适应刷新

发布于 2024-09-30 00:05:11 字数 271 浏览 2 评论 0原文

我在项目中使用 Flexigrid,我希望能够在网格刷新后保留选定的行。我在 Flexigrid 讨论板上问了同样的问题,得到了这个答案:

添加点击处理程序,如果选择了行的行 ID,则保存 id。刷新完成后,再次选择该行(如果仍然存在)

不知道如何继续,我什至不知道函数将是什么样子,所以这就是为什么我没有任何代码可以开始。

如果有人能指出我正确的方向,我将不胜感激。

谢谢,

克里斯蒂安。

I am using flexigrid in a project and I would like to be able to keep the selected rows after the grid is refreshing. I asked the same question on the flexigrid discussion board and I got this answer:

Add a click handler, save the id if the row id of the row selected. On refresh completion, select the row again (if still present)

Not sure how to proceed on this, I don't even know how a function will look like, so that's why I don't have any code to start with.

If someone could point me in the right direction will be greatly appreciated.

Thanks,

Cristian.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转身泪倾城 2024-10-07 00:05:11

Flexigrid 向选定的行添加了一个名为 trSelected 的类,因此每当网格上发生单击事件时,您都可以查找所有选定的行并以某种方式保存它们。下面是您可以执行的操作的一个简单示例:

var selectedRows = new Array();

$('#myGrid').click(function() {
    selectedRows = new Array();

    $(this).find('tr.trSelected').each(function(i, selectedRow) {
        selectedRows.push($(selectedRow));        
    });
});

Flexigrid adds a class called trSelected to selected rows, so whenever a click event happens on the grid you could just look for all the selected rows and save them in some way. Below is just a quick example of what you could do:

var selectedRows = new Array();

$('#myGrid').click(function() {
    selectedRows = new Array();

    $(this).find('tr.trSelected').each(function(i, selectedRow) {
        selectedRows.push($(selectedRow));        
    });
});
一抹微笑 2024-10-07 00:05:11

我编写了一些小代码来保持分页之间以及刷新期间的多重选择。

    $("#searchPhonoList").flexigrid($.extend({}, flexigridAttrs, {
        url: './rest/phono/search',
        preProcess: formatSearchPhonoResults,
        onSuccess: successSearchPhono,
        onSubmit: submit,
        method: 'GET',
        dataType: 'json',
        colModel : [
            {display: 'titre', name: 'titre_brut', width : 240,  sortable : true, align: 'left'},
            {display: 'version', name: 'version_brut', width : 60,  sortable : true, align: 'left'}
        ],
        height: "auto",
        sortname: "score",
        sortorder: "desc",
        showTableToggleBtn: false,
        showToggleBtn: false,
        singleSelect: false,
        onToggleCol: false,
        usepager: true, 
        title: "Liste des candidats",
        resizable: true,
        rp:20,
        useRp: true
    }));  

    var searchPhonoListSelection = new Array();

    $('#searchPhonoList').click(function(event){

        $(' tbody tr', this).each( function(){
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                searchPhonoListSelection.splice(searchPhonoListSelection.indexOf(id), 1);
            }
        });

        $('.trSelected', this).each( function(){
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) == -1  ) {
                searchPhonoListSelection.push(id);
            }
        });
    });


    function successSearchPhono() {
        $("#searchPhonoList tbody tr").each( function() {
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                $(this).addClass("trSelected");
            }
        });
    }

I have done small code to keep multi-selection between pagination and also during refresh.

    $("#searchPhonoList").flexigrid($.extend({}, flexigridAttrs, {
        url: './rest/phono/search',
        preProcess: formatSearchPhonoResults,
        onSuccess: successSearchPhono,
        onSubmit: submit,
        method: 'GET',
        dataType: 'json',
        colModel : [
            {display: 'titre', name: 'titre_brut', width : 240,  sortable : true, align: 'left'},
            {display: 'version', name: 'version_brut', width : 60,  sortable : true, align: 'left'}
        ],
        height: "auto",
        sortname: "score",
        sortorder: "desc",
        showTableToggleBtn: false,
        showToggleBtn: false,
        singleSelect: false,
        onToggleCol: false,
        usepager: true, 
        title: "Liste des candidats",
        resizable: true,
        rp:20,
        useRp: true
    }));  

    var searchPhonoListSelection = new Array();

    $('#searchPhonoList').click(function(event){

        $(' tbody tr', this).each( function(){
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                searchPhonoListSelection.splice(searchPhonoListSelection.indexOf(id), 1);
            }
        });

        $('.trSelected', this).each( function(){
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) == -1  ) {
                searchPhonoListSelection.push(id);
            }
        });
    });


    function successSearchPhono() {
        $("#searchPhonoList tbody tr").each( function() {
            var id = $(this).attr('id').substr(3);
            if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                $(this).addClass("trSelected");
            }
        });
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文