Add Remove Column Handler on jqGrid ColumnChooser

前端 未结 2 1714
天命终不由人
天命终不由人 2020-12-11 11:35

I\'m using the jqGrid columnChooser, like so:

    jQuery(grid).jqGrid(
        \'navButtonAdd\',
        pagerDiv,
        {
            caption: \"Columns\"         


        
相关标签:
2条回答
  • 2020-12-11 11:56

    I am using the below code in JqGrid for column chooser plug-in. when i tick the select All check box in the grid. I want to exclude particular column ( by default it should not display in my grid).
    I used hidden=True property in col model. buy i want to handle these in column chooser also.

    function Properties_Columnchooser() {
        $('#btn_setColumns').click(function () {
            jQuery('#grid-tableProperties').jqGrid('columnChooser',{
            "shrinkToFit" : true,
            "autowidth" : true,
            done : function(perm) {
                w = $(window).width();
                // alert('done ' + w);
                if (perm) 
                   {
                    this.jqGrid("remapColumns", perm, true);
                     this.setGridWidth(w - 30, true);
    
                    $('.ui-search-input').show();
                } 
                 else 
                {
                }
            }
        }
    );
        });
    }
    
    0 讨论(0)
  • 2020-12-11 12:01

    I think I understand your problem and find your question interesting, so I wrote the demo for you which shows how one can solve the problem.

    columnChooser uses jQuery UI Multiselect plugin internally which uses jQuery UI Sortable. So I suggest to use sortreceive event of the jQuery UI Sortable to catch the information needed.

    The code can be the following

    $("#grid").jqGrid('navButtonAdd', '#pager', {
        caption: "",
        buttonicon: "ui-icon-calculator",
        title: "Choose columns",
        onClickButton: function () {
            $(this).jqGrid('columnChooser');
            $("#colchooser_" + $.jgrid.jqID(this.id) + " ul.selected")
                .bind("sortreceive", function (event, ui) {
                    alert('column "' + ui.item.text() + '" is choosed');
                });
            $("#colchooser_" + $.jgrid.jqID(this.id) + " ul.available a.action")
                .click(function () {
                    alert('column "' + $(this).parent().text() + '" is choosed');
                });
    
        }
    });
    

    See the demo here.

    The code bind 'click' event on the "+" for the initial list of the columns which was in the column chooser at the initialization time of the dialog. I think it would be sufficient for you. If needed you can easy modify the code to support the 'click' on the "+" for the columns which will be removed from the left list during the work with the columnChooser.

    I almost forget to mention that I used in the demo improved version of the columnChooser (see the answer), but my above suggestion works with the original version of columnChooser too.

    0 讨论(0)
提交回复
热议问题