Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Selecting Multi-Select Options on Edit Popup
05/10/2009
22:52
Avatar
andrewwatts
Member
Members
Forum Posts: 10
Member Since:
06/10/2009
sp_UserOfflineSmall Offline

How do you pre-select multiple options in a multi-select by default in an Edit Popup Form?

So, if the grid displays “One, Three” in a column and editoptions is

{multiple: true, size: 3,value: {0: '', 1: 'One', 2: 'Two', 3: 'Three'}}

as defined in ColModel for the grid column. Then the following select markup is rendered:

<select>
<option value="0"></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Which works Great

However, the in the DOM select.selectedIndex is 1, which renders differently in the UI than the other options. And, I really want 1 and 3 selected so that if the user doesn't modify the options and clicks 'Submit' then the options don't change. This way if the click Submit then the options changes from 1,3 to 1, which is undesired behavior.

Is there a way to pre-select both option 1 and 3, so that if the user doesn't modify the options and clicks 'Submit' then the options do not change.

Thanks

06/10/2009
06:45
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

If you are in add mode you can use the defaultValue in edit option defined like this

defaultValue : "1,3" or defaultValue : "One,Three" - both will work.

If you are in edit mode alll depends on data in the grid.

1. If the table cell is empty a defaultValue is used.

2. If the table cell is not empty a comma separated values are accepted which are selected in the form

So by example if the cell contain

Two, Three - the second and third options will be selected.

Reagrds

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

06/10/2009
13:19
Avatar
andrewwatts
Member
Members
Forum Posts: 10
Member Since:
06/10/2009
sp_UserOfflineSmall Offline

Thanks for the suggestion, unfortunately that didn't work, so I did a little digging and think I found a couple bugs, or if not, then, I don't understand... But an explanation of what I am seeing would be much appreciated along with any potential workarounds.  I tried to create as small of an example as possible to show what I am experiencing.  below is the code along with the discoverys I made while digging into this.

Thanks for the help.

- Andrew

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jQuery Grid Multi-Select</title>
       
        <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.7.2.custom.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
       
        <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript" src="js/i18n/grid.locale-en.js"></script>
        <script type="text/javascript" src="js/jquery.jqGrid.min.js"></script>
       
        <script type="text/javascript">
           
            /**
             *
             * discoveries:
             *
             * 1. Only works second time edit popup is opened, eg:
             *      - refresh page to get a new state
             *      - select row 2
             *      - click the edit button
             *      - notice only 'Three' is selected (or last in list)
             *      - close popup
             *      - make sure row 2 is still selected
             *      - click the edit button
             *      - now 'One' and 'Three' are selected (or all in list)
             *        correctly as expected
             *       
             *    Seems like there is bug the very first time the popup is
             *    opened.
             *
             * 2. Add a custom formatter to render the select in the grid
             *    column and only the first option shows up. eg:
             *      - uncomment the formatter
             *      - refresh the page
             *      - select row 2
             *      - click the edit button
             *      - notice only 'Three' is selected (or last in list)
             *        same as above
             *      - close popup
             *      - make sure row 2 is still selected
             *      - click the edit button
             *      - now only 'One' is selected (or first in list) and this
             *        behavior continues, never selecting all options.
             *       
             *    Seems like there is also a bug related to adding a formatter
             *    to render the column
             *   
             */
           
            jQuery(document).ready(function(){

                var select_values = {'0':'','1':'One','2':'Two','3':'Three'};
               
                jQuery("#grid_list").jqGrid({
                    datatype: "local",
                    height: 100,
                    colNames: ['Id', 'Name', 'Values'],
                    colModel: [{
                        name: 'id',
                        index: 'id',
                        width: 100,
                       
                    }, {
                        name: 'name',
                        index: 'name',
                        width: 100,
                        editable: true
                    }, {
                        name: 'values',
                        index: 'values',
                        width: 200,
                        editable: true,
                        edittype: 'select',
                        editoptions: {
                            multiple: true,
                            size: 4,
                            value: select_values,
                            defaultValue: '0'
                        }
                        // uncomment the formatter to see the error described in
                        // discovery 2
//                        ,formatter: function(cv, o, ro){return cv.join(', ');}
                    }],
                    caption: 'Multi-Select Test',
                    pager: jQuery('#grid_pager')
                }).navGrid('#grid_pager',
                    {add: true, del: false, edit: true, refresh: false, search: false, view: false},
                    {/* edit options */},
                    {/* add options */},
                    {/* delete options */},
                    {/* search options */},
                    {/* view options */}
                );
               
                var mydata = [
                    {id:"1",name:"test1",values:['One']},
                    {id:"2",name:"test2",values:['One','Three']},
                    {id:"3",name:"test3",values:['Two']}
                ];
               
                for (var i = 0; i <= mydata.length; i++)
                    jQuery("#grid_list").addRowData(i + 1, mydata[i]);
            });
        </script>
       
    </head>
    <body>
        <table id="grid_list" class="scroll" cellspacing="0" cellpadding="0"></table>
        <div id="grid_pager" class="scroll"></div>
    </body>
</html>

07/10/2009
03:58
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Andrew,

First of all Thank you very much for this investigation and finding bugs. Yes, we have these two bugs.

Short: they are corrected in GitHub (Note that the correction is in 3.6 branch and not in master).

It is quiete easy to work this way.

Thank you very much again.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

07/10/2009
12:10
Avatar
andrewwatts
Member
Members
Forum Posts: 10
Member Since:
06/10/2009
sp_UserOfflineSmall Offline

Thanks Tony, I'll take a look at the 3.6 branch.  Is there a scheduled release date or timeframe for 3.6?

09/10/2009
03:50
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Yes, next week I will publish the beta and hope that after maximum two weeks we will have 3.6

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

25/02/2011
15:44
Avatar
caiorg
New Member
Members
Forum Posts: 1
Member Since:
25/02/2011
sp_UserOfflineSmall Offline

tony said:

Hello,

Yes, next week I will publish the beta and hope that after maximum two weeks we will have 3.6

Regards

Tony


Hey Tony,

I'm using jqGrid 3.8.2 and still facing this bug. It's exactly what Andrewwatts described above.

Is there any possibility the bug return somehow after you fixed it on 3.6?

Cheers

Caio

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
80 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information