1

I have a grid populated by a database. One of the columns is a concat of 2 columns in another table. In this case it is a team's location and name. However, when I click on edit and the edit form gets populated, it always picks the first team in the dropdown as opposed to the actual team in the database.

Here is some of the relevant code:

jQuery("#listPlayer").jqGrid({
    url:'../controller/playerGrid.php',
    datatype: "json",
    colNames:['ID','First Name','Last Name', 'Team'],
    colModel:[
            {name:'id',         index:'id',         width:20,   editable:false, hidden:true},
            {name:'first_name', index:'first_name', width:80,   editable:true, editrules: {required: true}},
            {name:'last_name',  index:'last_name',  width:80,   editable:true, editrules: {required: true}},
            {name:'idTeam',     index:'idTeam',     width:50,   editable:true, editrules: {required: true}, edittype: 'select', editoptions: { dataUrl: "../controller/listTable.php?query=team" } }
    ],
    rowNum:50,
    rowTotal: 2000,
    rowList : [20,30,50],
    mtype: "POST",
    rownumbers: true,
    rownumWidth: 40,
    gridview: true,
    pager: '#pagerPlayer',
    sortname: 'last_name',
    viewrecords: true,
    sortorder: "asc",
    caption: "Player Manager",
    editurl: "../controller/playerEditGrid.php"

And this is what the SQL query in listTable.php looks like:

SELECT t.id, CONCAT(t.location, ' ', t.name,' (', l.abbr, ')' ) as idTeam FROM team t, league l WHERE t.idLeague = l.id ORDER BY t.location

I know the problem lies in the fact that it's a concatenation as opposed to a single column but I'm sure there's a way around it... I just don't know it.

Falantar014
  • 405
  • 2
  • 5
  • 20

1 Answers1

1

I haven't used it this way but the following part of jqgrid help should be applicable for your case: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#select

The return from your dataurl should already be a valid HTML select element like:

<select> 
<option value='1'>One</option> 
<option value='2'>Two</option> 
...
</select>

refer 3. Setting the editoptions dataUrl parameter in the above url.

hope this helps!

justcurious
  • 186
  • 1
  • 7
  • Yes I am already using dataUrl and it is able to generate a proper dropdown. The problem I'm facing lies in the edit form. Because what is being displayed in my grid is different from the dropdown list, when I click on edit, it doesn't remember which team the player belongs to. – Falantar014 Apr 27 '12 at 13:10
  • @Falantar014: your grid source url is diff from dataurl, so I'm guessing the *idTeam* value on the grid is diff from the select:option values on the edit form. If that is the case, you would have to use the [buildselect](http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3acommon_rules#editoptions) option so that the text of the select:option is the friendly text and the value of it matches the value on the grid. this [answer](http://stackoverflow.com/questions/4101116/asp-net-mvc-post-call-returning-string-need-help-with-format-for-jqgrid/4102155#4102155) might help you out with *buildselect* – justcurious Apr 27 '12 at 22:14