2

Dialog

Please find the column reordering and column chooser dialog as used with jqGrid when used with a ui.multiselect.js.

I want to alter the style of the ui.multiselect plugin without altering the js file. Just want to override a few things. Firstly I want the two column headers to be at same level height - 6 items selected and right side column header Add all. I wan to change the text for 6 items selected to Avlialble Columns and right column header to Hidden Columns. How can this be done by overriding the ui.multiselect plugin in a separate file (js) so when I call grid.jqGrid('columnChooser') it automacially applies the overriden styles.

chugh97
  • 9,602
  • 25
  • 89
  • 136

1 Answers1

4

First of all I find your question very interesting, so +1 from me.

One thing from the picture, which you posted and which is not directly the part of your question, seems me a little strange: the Column Chooser dialog has no resizable part at the right bottom corner of the dialog. It could be some additional settings which you use. I personally find better to have the dialog resizable.

Now back to your main question. To change the default texts 'items selected', 'Add all' and 'Remove all' you can use the following code:

$.extend($.ui.multiselect, {
    locale: {
        addAll: 'Make all visible',
        removeAll: 'Hidde All',
        itemsCount: 'Avlialble Columns'
    }
});

Additionally you can consider to change the width of the Column Chooser dialog and the proportions between the left and the right panel with

$.extend(true, $.jgrid.col, {
    width: 500,
    msel_opts: {dividerLocation: 0.5}
});

or set the same parameters in the call of the columnChooser:

$grid.jqGrid('navButtonAdd', '#pager', {
    caption: "",
    buttonicon: "ui-icon-calculator",
    title: "Choose columns",
    onClickButton: function () {
        $(this).jqGrid('columnChooser',
            {width: 500, msel_opts: {dividerLocation: 0.5}});
    }
});

As the results you will have the dialog like

enter image description here

see the demo.

You can additionally consider to disable the searchable field of the column chooser if you don't plan to use it. It will save the width in the dialog:

$.extend(true, $.ui.multiselect, {
    defaults: {
        searchable: false
    },
    locale: {
        addAll: 'Make all visible',
        removeAll: 'Hidde All',
        itemsCount: 'Avlialble Columns'
    }
});

UPDATED: If you need some additional customization in the Column Chooser dialog you can do the changes manuallyafter the dialog is created. For example the results of the code

$(this).jqGrid('columnChooser',
    {width: 550, msel_opts: {dividerLocation: 0.5}});
$("#colchooser_" + $.jgrid.jqID(this.id) + ' div.available>div.actions')
    .prepend('<label style="float:left;position:relative;margin-left:0.6em;top:0.6em">Search:</label>');

will be the following:

enter image description here

see the corresponding demo here.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I know these settings, my problem is adding Column Heading on the right column saying "Hidden Columns" and also a label tag before the search textbox called Search: – chugh97 Jan 24 '12 at 14:37
  • 1
    @chugh97: If you *know* the settings, why you ask "I wan to change the text for 6 items selected to Avlialble Columns"? You didn't wrote anything about "Search:" label before the search textbox in the text of your question. It seems absolutely new requirement. Isn't so? About "Hidden Columns" header: I don't understand where you want to add this. Where you see place for the headers? – Oleg Jan 24 '12 at 15:15
  • Basically I want to customize by adding custom table headers and text so I am in control of DOM inside the dialog box. – chugh97 Jan 24 '12 at 15:27
  • @chugh97: I updated my answer with suggestion how to add "Search:" label before the search textbox. Other customization you can do in the same way. Another remark: I don't know where are you from, so it could be language specifics. Nevertheless, if somebody spent his time in writing an answer for you and helps you for free, it would be polite to write "thanks" and not start with your comments with additional requirements. – Oleg Jan 24 '12 at 16:45
  • Thanks very much for your reply.You have always been a star! I think you may be right that it may be language specifics. I am from India. Do you by any chance work for jQGrid. Your support has been tremendous...Sorry for misunderstanding..I appreciate your responses. – chugh97 Jan 24 '12 at 19:56
  • @chugh97: You are welcome! I am from Russian and many people in Russian are not well brought up and polite. Nevertheless after leaving 20 years in Germany it's prevents me. I think it's always better to tell about the things which are in the way as to remain silent and be offended. In the most cases the problem come just from misunderstanding. So after the talk everybody understand each other better and there are no more misunderstanding at the end. I am glad to help you and other people and I need not more words as "thanks", but the word I really need. Best regards. – Oleg Jan 24 '12 at 21:09
  • I noticed one thing on the ui.multiselect dialog box - column selector that you cannot drag from visible to hidden columns but you can drag from hidden to visible columns. Is this a limitation of the ui.multiselect.js plugin. I think what I need is a consistent way of drag and drop across hidden to visible and visible to hidden columns. Comments would be appreciated. – chugh97 Jan 27 '12 at 16:42
  • @chugh97: To make a column hidden one can click on '-' on the corresponding column. Reordering of the hidden column has no sense because the column stay hidden. If you need to make visible some currently hidden column you can either click on the '+' to add it *at the end* of the list of visible columns or you can grad any hidden column and by dropping make it not only visible, but to specify its position in the list of the visible columns. So the list of hidden columns is *only dragable*. The list of visible columns is both *dragable and dropable*. – Oleg Jan 27 '12 at 17:00
  • I suppose you are right but I have a requirement where the hidden column region is also droppable. I don't have to reorder columns which are hidden but certainly want to drag a visible column to hidden region and drop it. So it's consistent at both ends. Sorting hidden columns not required. How easy would it be to implement this? – chugh97 Jan 27 '12 at 18:11
  • @Oleg: Hey, can you help me with something. I want to use this plugin for a project of mine within the featured posts section. I want to dynamically get unfeatured posts in right column and featured posts in left column. Also, when I click to unfeature a post, how can I track which post id was unfeatured as unchecked values are not sent on form submission. Thanks – Assad Nazar May 12 '12 at 11:40
  • @booota: If I understand you correct you will find the answer on your question [here](http://stackoverflow.com/a/10439808/315935). If the answer is not what you need you should better open new question and describe detailed your problem. – Oleg May 12 '12 at 11:58
  • @Oleg: Yes it is. Can you also tell me that how can i use it in https://github.com/michael/multiselect/ as it does not support onClickButton event. – Assad Nazar May 12 '12 at 12:25
  • @booota: Sorry, it's difficult to understand what you mean. Which "button" you mean for `onClickButton`? In [the answer](http://stackoverflow.com/a/10439808/315935) which I referenced I shown how to bind "+" (which will be addressed as `$("#colchooser_" + $.jgrid.jqID(this.id) + " ul.available a.action")`). In the same way one can bind `click` event on "-" from the left list of chosen columns. I can repeat that if you have unclear questions please describe all **detailed** (better in the new question where you will have more place and possibilities to include code or pictures if it's needed). – Oleg May 12 '12 at 13:11
  • I'm using jqgrid 3.6, jquery 1.9, jquery-ui 1.10, but the "Add All" is not working as expected. It behaves just like "Hide All". The demo is perfect, I'm just wondering if there are any known issues with the "Add All" – Paul Apr 15 '13 at 02:27
  • 1
    @Paul: retro version 3.6 of jqGrid is very very old. It's not compatible with jQuery 1.9.x, jQuery UI 1.10.x. You should [download](http://www.trirand.com/blog/?page_id=6) and use jqGrid 4.4.5. – Oleg Apr 15 '13 at 04:59