Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:24:42+00:00 2026-06-15T08:24:42+00:00

I’m quite the beginner in jQuery and I’m trying to get a simple columnChooser

  • 0

I’m quite the beginner in jQuery and I’m trying to get a simple columnChooser to work for jqGrid.
I’m using jqGrid’s navigation bar to insert an “Add/remove columns” button, and on the click event of this button I display the column chooser. Having loaded the multiselect plugin before, it uses it to display the columns with checkboxes.

Here is my code:

$("#myGrid")
    .jqGrid({
        ...
        toppager: true,
        pager: jQuery('#myPager'),
        ...
    })
    .jqGrid('navGrid', "#myPager", { //add the navigator (defaults to the bottom of the grid)
        edit: false, add: false, del: false, search: false, refresh: false, //remove all default buttons
        cloneToTop: true //clone it, so a new one is created on top of the grid (name of the clone is <id of grid>_toppager)
    })
    .jqGrid('navButtonAdd', "#myGrid_toppager", { //add a custom button to the cloned navigator
        caption: "show/hide columns",
        onClickButton: function () {
            var colChooser = $("#colchooser_myGrid");
            if (colChooser.length == 0) {
                $("#myGrid").jqGrid('columnChooser', {
                    width: 260,
                    height: 220,
                    classname: "column-chooser",
                    msel_opts: {
                        autoOpen: true,
                        header: false,
                        height: "auto",
                        classes: "column-chooser" },
                    dlog_opts: { modal: true, resizable: false }
                });
            }
            else {
                // ??
            }
        }
    });

And my CSS:

.column-chooser .ui-multiselect-checkboxes {
    overflow-y: hidden;
}

I am stuck with three things:

  • the buttons (OK and Cancel) are not visible. I don’t find them anywhere on the inner html code. When I remove the options, they appear, but the multiselect does not resize to fit the columnChooser dialog.
  • how do I get the multiselect to be “unclosable”? I tried adding beforeclose: function () { return false; } in the msel_opts object, and it works, but then the multiselect values stay visible always, even when closing the dialog.
  • the dialog only displays once, then refuse tho whow up again. It seems it’s because it has been created, but it seems the jqGrid calls destroy on both the dialog and the multiselect, so I cannot show them again.

I am using jquery 1.4.4, jquery-ui 1.8.18, jqgrid 4.3.1 and multiselect 1.12, all tested under Firefox 11.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:24:45+00:00Added an answer on June 15, 2026 at 8:24 am

    Here’s the code I ended up writing to add a column chooser to a grid:

    var navButton = {
        caption: window.Constants.Grid.ShowHideColumns,
        onClickButton: function () {
            $(context.grid).jqGrid('columnChooser', {
                width: 260,
                height: 280,
                classname: "column-chooser",
                msel_opts: { //multiselect options
                    autoOpen: true,
                    header: false,
                    height: "auto",
                    classes: "column-chooser",
                    beforeclose: function () { return false; } //keep multiselect drop down open  
                },
                dlog_opts: { //dialog options
                    modal: false,
                    resizable: false,
                    draggable: false,
                    dialogClass: "column-chooser",
                    buttons: [
                        {
                            text: window.Constants.Dialog.OK,
                            click: function() {
                                var colModel = $(context.grid).jqGrid("getGridParam", "colModel");
                                $(".column-chooser .ui-multiselect-checkboxes li input[type=checkbox]").each(function () {
                                    var colName = colModel[parseInt($(this).val(), 10)].name;
                                    $(this).attr("checked") ? $(context.grid).showCol(colName) : $(context.grid).hideCol(colName);
                                });
                                $(this).dialog("close");
                            }
                        },
                        { text: window.Constants.Dialog.Cancel, click: function () { $(this).dialog("close"); } }
                    ],
                    close: function () {
                        $(".column-chooser").remove(); //remove all elements
                        PopupBox.hideFullOverlay();
                    }
                }
            });
    
            PopupBox.showFullOverlay();
        }
    };
    
    var pager = $(context.grid).jqGrid("getGridParam", "pager");
    $(context.grid)
        .jqGrid("navGrid", pager, { edit: false, add: false, del: false, search: false, refresh: false, cloneToTop: true }) //add a nav grid to the pager and top pager
        .jqGrid("navButtonAdd", pager, navButton) //add column button to pager
        .jqGrid("navButtonAdd", context.grid + "_toppager", navButton); //add column button to top pager
    

    So in this code context.grid is the id of the grid, and this code gets called after the creation of the grid (i.e. after a line looking like $(context.grid).jqGrid({ /* insert colmodel, pager name, etc */ }))

    Here is what is being done against all of my issues:

    • OK and Cancel buttons not visible: specified the buttons in the options
    • getting the multiselect to be unclosable: leave the return false in beforeclose, but remove the select from the page with the close element in dlog_opts. Somehow the select stays in the page (as child to the root node).
    • Solving the fact that the chooser didn’t show twice: same thing. Remove all elements when the dialog is closed.

    I do this by setting the same class on every created object (the multiselect, the chooser, the dialog). When I’m done using it, I remove everything from my html using this class.

    The root problem is that jqGrid doesn’t create a proper html hierarchy for the elements, probably because of the way the multiselect plugin works (it hides the select element and creates an ul list next to it containing the checkboxes). In the end, I find myself with 3 divs, one containing the dialog, one containing the ul and one containing the select, all direct children of the body element. When closing, jqGrid leaves the select element, and that breaks it the second time I open the chooser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.