jqGrid列选择器-按字母顺序在右侧未选中的列

  • 本文关键字:顺序 选择器 列选 jqGrid jqgrid
  • 更新时间 :
  • 英文 :


我一直在使用jqGrid,一切都很好(排序、重新排序列、在columnChooser中添加/删除列、在columnChooser中重新排序列…)。不过,还有一件小事。

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

Id、名称、日期(隐藏)、A值、B值、C值(隐藏)

现在,当我打开columnChooser时,可见的列将按网格中显示的预期顺序显示在左侧。右侧不可见的列显示为:日期、CValue。如果我从网格中删除所有列,那么列选择器对话框右侧未选中列的顺序如colModel:Id、Name、Date。。。

我希望看到选中的列按屏幕上显示的顺序进行重新排序,但我希望右侧未选中的列始终按字母顺序显示——这可能吗?

我很难实现这一点,但最终决定将自己的事件处理程序添加到对话框中,以手动对右侧进行排序。

//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);
}

最新更新