1

I've got a subgrid that, when you click the "+" sign next to "Cheese", the ajax query fires, and I see the subgrid column names, but the actual data isn't populated into the subgrid. The problem happens regardless of which grid I try to expand, but the "Cheese" example is the one shown below.

You can see the XML response in the bottom portion of the FireBug output in the screenshot. I've read through that XML, and it looks to be valid. On a hunch, I also pasted the XML output into this page, and it seems to indent just fine. On top of that, I also had the ajax call return some very basic values, and no matter what I've tried so far, the grid remains empty.

enter image description here

What you should see in the subgrid is:

------------------------------------------------------
|Translations                    | Language | Active |
------------------------------------------------------
| It's cheesy goodness           |   EN     |   No   |
| fromage                        |   FR     |   No   | 
|                                |   DE     |   N/A  |   <-- "N/A" means there's no translation of "cheese" in German, currently in the database

    ... etc., with all supported languages listed.

The code for the subgrid is:

$("#translationsList").jqGrid({
    caption : "Translations",
    datatype : "xml",
    url : translationsFeed,
    editurl : translationsEdit,
    mtype : "get",
    pager : "#translationsPager",
    rowNum : 20,
    autowidth : true,
    sortname : "phrase",
    sortorder : "asc",
    viewrecords : true,
    multiselect : false,
    hidegrid : false,
    height : 300,
    altRows : true,
    rownumbers : true,
    toolbar : [false],
    colNames : ["phrase_id", "translation_id", "language_cd", "Phrase", "Translation", "Created", "Modified", "Active"],
    colModel : [
            { name : "phrase_id",                                   index : "phrase_id",            sortable : true,    search : false, editable : true,    edittype : "text",      editrules: { edithidden :true },                                    hidden : true},
            { name : "translation_id",                          index : "translation_id", sortable : false, search : false, editable : true,    edittype : "text",      editrules: { edithidden :true },                                    hidden : true},
            { name : "language_cd",                                 index : "language_cd",      sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { edithidden: true, required : true }, hidden : true },
        { name : "Phrase",              width:200,  index : "phrase",               sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { required : true } },
        { name : "Translation",         width:200,  index : "translation",      sortable : true,    search : true,  editable : true,    edittype : "text",      editrules: { required : false } },
        { name : "Created",             width:100,  index : "modify_dt",            sortable : true,    search : true },
        { name : "Modified",            width:100,  index : "create_dt",            sortable : true,    search : true },
        { name : "Active",              width:20,       index : "active",               sortable : true,    search : true,  editable : true,    edittype : "select",    editoptions:{value:"0:No;1:Yes"} }
    ],
    onSelectRow: function(id) {
            jQuery('#translationsList').editRow(id, true);
    },
    subGrid: true,
    subGridUrl: 'ajax/translations_subgrid_feed.php',
    subgridtype: 'xml',
    subGridModel : [{
      name      : ['Translations', 'Language', 'Active'],
      width     : [583, 70, 80],
      align     : ['left','right','right'],
      params    : ['phrase_id']
    }],
  subGridOptions: {
    plusicon : "ui-icon-plus",
    minusicon : "ui-icon-minus",
    openicon: "ui-icon-carat-1-sw",
    expandOnLoad: true,
    selectOnExpand : false,
    reloadOnExpand : true
  }
});

The XML response for the main/subgrids can be found in this Gist

jefflunt
  • 33,527
  • 7
  • 88
  • 126
  • Could you post the XML response from the `translationsFeed` URL and XML response of subgrid 'ajax/translations_subgrid_feed.php' after one clicks on the 'Cheese'? The typing of XML based on the picture is not nice job. Having both XMLs one can easy reproduce your problem. – Oleg Jun 23 '11 at 20:47
  • Sure: https://gist.github.com/1043635 I also added it to the end of the question there. – jefflunt Jun 23 '11 at 21:10

1 Answers1

1

I could reproduce the problem and analysed the code of subgrid module of jqGrid. My explanation is: the new expandOnLoad: true property of the subGridOptions which you use can work only in case of 'local' datatype on the main grid. I don't found the corresponding remark about this in the documentation, but it is so.

In the version 4.1 are used delayOnLoad option, but it didn't works correct. In the version 4.1.1, after the fix the option are not used and immediately after adding a row in the main grid. The problem is that jqGrid use .grid.hDiv.loading property to skip ajax request if the response of the previous ajax request are not processed till the end. Inside of beforeSend handler of the $.ajax request of the main grid (see here) will be called beginReq() which first line is

ts.grid.hDiv.loading = true;

then inside of success handler of the $.ajax request the addXmlData method will be called, which call addSubGrid for every row of the main grid, which call .trigger('click'); on the "expand" icon of the grid row. As the result the populatesubgrid will be called on all grid rows before the .grid.hDiv.loading will be chaned to false inside of endReq at the end of success handler. So in the corresponding part of the populatesubgrid method where the ts.grid.hDiv.loading will be tested the corresponding $.ajax call will be skipped and the rows will be not expanded.

So I can repeat the short result of my analyses: don't use expandOnLoad: true option. It is not work on remote data.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • So, what I'm gathering from that is: (1) don't use 'expandOnLoad: true' with remote data (which I've changed to false), and (2) make sure I'm using the latest version of jqGrid. These two steps together have resulted in no change. Can you post your working code sample, so I can compare it against what I've got? And thank your for taking the time to look into this! – jefflunt Jun 24 '11 at 14:29
  • @normalocity: No problem. Look at [here](http://www.ok-soft-gmbh.com/jqGrid/SubgridNormalocity.htm) – Oleg Jun 24 '11 at 14:46
  • Hm, I must have some other problem. I modified my page to match yours, and it still has the same problem. I then created a new page that contained the exact HTML from your page, and adjusted my grid/subgrid URLs to point to my files, and I still have the same problem. I've also compared my jqGrid code to yours, line-by-line, and still no go. HOWEVER, the code/page sample you posted works perfectly. – jefflunt Jun 24 '11 at 15:24
  • Next thing I'm doing is copying your XML files as well, and testing again. – jefflunt Jun 24 '11 at 15:30
  • Ok, it seems I have a problem with my XML, or the way I'm sending the response. I plugged in your XML file for the subgrid, and BINGO! – jefflunt Jun 24 '11 at 15:31
  • @normalocity: You should compare the HTTP headers especially the `Content-Type`. You can use [Fiddler](http://www.fiddler2.com/fiddler2/) of [Firebug](http://getfirebug.com/) to examine the HTTP headers. – Oleg Jun 24 '11 at 15:39
  • That was it - headers weren't set properly! Holy crap, thank you. – jefflunt Jun 24 '11 at 15:47