Forum

July 12th, 2025
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
Can't get "url" parameter passed to grid
15/09/2010
20:57
Avatar
jmcleod3
Member
Members
Forum Posts: 33
Member Since:
04/05/2009
sp_UserOfflineSmall Offline

Hello all,

I have a grid that works fairly well.  Now, I wish to have a dynamic url.

For example,

http:www.mysite.com/getgame.php?id=123

This will change based on the id.

Within the grid, I have the 'url' set to the page name (getgame.php)

[CODE]

jQuery("#contacts").jqGrid({
    url:"getgame.php",
    datatype: 'json',
    colNames:['Contact No','Last Name', 'First Name', 'Type','Email','Phone', 'Fax', 'Note'],
    colModel :[
      {name:'member_contacts_id',
           index:'member_contacts_id',
           width:100,
           hidden:true,
           editable:false,
           editoptions:{
               readonly:true,
               size:10
           }
       },
      {name:'last', index:'last', width:120, align:'right', editable:true,editoptions:{size:30}},
      {name:'first', index:'first', width:120, align:'right', editable:true,editoptions:{size:30}},
      {name:'type',
               index:'type',
               width:70,
            hidden:true,
            editable: true,
            edittype:"select",
            editoptions:
            {
                value:"Coach:Coach;Trainer:Trainer;Referee:Referee"
            },
            editrules:{edithidden:true}
      },
      {name:'email', index:'email', width:200, align:'right', editable:true,editoptions:{size:30}},
      {name:'phone', index:'phone', width:110, align:'right', editable:true,editoptions:{size:30}},
      {name:'fax', index:'fax', width:110, align:'right', editable:true,editoptions:{size:30}},
      {name:'note',
             index:'note',
             width:100,
             sortable:false,
             hidden:true,
             editable: true,
             edittype:"textarea",
             editoptions:{rows:"5",cols:"30"},
            editrules:{edithidden:true}
      }
    ],
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'member_contacts_id',
    sortorder: 'asc',
    viewrecords: true,
    caption: 'Contacts',
    height:"100%",
    editurl:"_editContacts.php'",
    
    grouping: true,
       groupingView : {
           groupField : ['type'],
           groupColumnShow : [false],
           groupText : ['<b>{0} - {1} Contact(s)</b>'],
           groupCollapse : true,
        groupOrder: ['asc'],
        groupDataSorted : true
       }
  });

[\CODE]

How do I set and pass the id number that will change?

Thank you for any help with this.

John

It's not who I am underneath, but what I do that defines me.

15/09/2010
22:42
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

First of all you should be careful with the usage of url in the form "http:www.mysite.com/getgame.php?id=123" because of Same Origin Policy restrictions. You can get per ajax only data from the same web site. So to have the problem no time you should use always url without protocol, domain and port prefix: "/blabla/getgame.php?id=123" or "getgame.php?id=123".

Because you use HTTP GET for requests to the server and you want append the url with additional parameter "id=123" you can do this without modification of url. Just use postData option of jqGrid

postData: {id: 123}

or

postData: {id: myId}

where myId is a var which has the value which you need (like 123).

You can also use functions as a value of some postData properties like

postData: {id: function() {
        if (jQuery("#onlyMySw").is(':checked')) {
            return 123;
        } else {
            return 456;
        }
    }
}

The last approach has a large advantage, because the function will be called every time during grid refresh (for example, in case of choose new sort order or switching between pages and so on. In the example above the url will be appended with parameter id=123 if checkbox with id="onlyMySw" is checked and with id=456 if it is not checked.

To read more about the last approach see my answer on the stackoverflow.com.

Best regards
Oleg 

16/09/2010
15:57
Avatar
jmcleod3
Member
Members
Forum Posts: 33
Member Since:
04/05/2009
sp_UserOfflineSmall Offline

Thanks for the quick reply, Oleg.

Your solution helped me very much.

Do you think that there's a similar solution for the 'editurl'?

Thanks again,

John

It's not who I am underneath, but what I do that defines me.

16/09/2010
17:36
Avatar
jmcleod3
Member
Members
Forum Posts: 33
Member Since:
04/05/2009
sp_UserOfflineSmall Offline

Solved the problem.

Within the navGrid, I added "editData:{id:value}" in the add, edit options.

jQuery("#contacts").jqGrid('navGrid','#pager',
        {search:false,view:true}, //options
        {jqModal:true,checkOnUpdate:true,savekey: [true,13], navkeys: [true,38,40], checkOnSubmit : true, reloadAfterSubmit:false, closeOnEscape:true, bottominfo:"Fields marked with (*) are required", width: 400, editData:{id:value}}, // edit options
        {jqModal:true,checkOnUpdate:true,savekey: [true,13], navkeys: [true,38,40], checkOnSubmit : true, reloadAfterSubmit:false, closeOnEscape:true,bottominfo:"Fields marked with (*) are required", width: 400, editData:{id: value}}, // add options
        {reloadAfterSubmit:false,jqModal:false, closeOnEscape:true}, // del options
        {}, // search options
        {navkeys: [true,38,40], height:250, width: 300,jqModal:false,closeOnEscape:true} // view options
      )
  });

John

It's not who I am underneath, but what I do that defines me.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 994

Currently Online:
30 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