jqGrid columnChooser - 右侧未选中的列,按字母顺序排列

时间:2012-07-17 16:31:48

标签: jqgrid

我一直在使用jqGrid,一切正常(列的排序,重新排序,在columnChooser中添加/删除列,重新排序columnChooser中的列,......)。但是有一件小事。

看来,我传递给网格的colModel的初始列表按照它们显示的顺序包含列,包括可能的隐藏列的列表,例如,列:

ID,姓名,日期(隐藏),AValue,BValue,CValue(隐藏)

现在,当我打开columnChooser时,可见列以预期顺序显示在左侧,因为它们出现在网格中。不可见的列显示在右侧:Date,CValue。如果我从网格中删除所有列,则列选择器对话框右侧未选定列的顺序如colModel中所定义:Id,Name,Date,...

我希望在屏幕上显示顺序中的所选列以进行重新排序,但我希望右侧未选择的列始终按字母顺序显示 - 这是否可能?

1 个答案:

答案 0 :(得分:0)

我无法使其工作但最终决定将自己的事件处理程序添加到对话框中以手动对右侧进行排序。

//Add the button to the jqGrid toolbar
$('#MyGridId').jqGrid('navButtonAdd', '#MyGridToolbar', {
    buttonicon: 'ui-icon-transferthick-e-w',
    caption: 'Select Columns',
    title: 'Select Columns',
    onClickButton: function () {
        $(this).jqGrid('columnChooser', {
            done: function (perm) {
                if (perm) {
                    this.jqGrid('remapColumns', perm, true);
                }
            }
        });

        //Setup custom event bindings and give the right side an initial sort
        BindColPickerActions($.jgrid.jqID(this.id));
        SortColPickerAvailable($.jgrid.jqID(this.id));
    }
});

//function to add click event bindings to the dialog actions
function BindColPickerActions(gridId) {
    var colpickerId = 'colchooser_' + gridId;

    //When moving an item from selected to available (Hiding)
    $('#' + colpickerId + ' .selected a:not(.SortModifier)').bind('click', function(){
        SortColPickerAvailable(gridId);
        BindColPickerActions(gridId);
    });

    //When moving an item from available to selected (Showing)
    $('#' + colpickerId + ' .available a:not(.SortModifier)').bind('click', function(){
        BindColPickerActions(gridId);
    });

    //add a class to the actions that have been modified to keep track
    $('#colchooser_' + colpickerId + ' .available a:not(.SortModifier), #' + colpickerId + ' .available a:not(.SortModifier)').addClass('SortModifier');
}

//function to sort the available list
function SortColPickerAvailable(gridId) {
    //get the list of li items
    var colpickerId = 'colchooser_' + gridId;
    var available = $('#' + colpickerId + ' .available .connected-list');
    var li = available.children('.ui-element');

    //detatch and sort the li items
    li.detach().sort(function(a, b) {
        return $(a).attr('title').toUpperCase().localeCompare($(b).attr('title').toUpperCase());
    }); 

    //re-attach the li items           
    available.append(li);
}
相关问题