0

I have fixed row numbers to 10 for my subgrids, but if reccount is less than 10 I would want to adjust height subgrid to "auto" or "100%".

So here is my code for this subgrid :

//  SUBGRID FOURTH LEVEL
var subgrid_table_id = subgrid_id+"_d",
    pager_id = "p_"+subgrid_table_id; 
$("#"+subgrid_id).append("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
$("#"+subgrid_table_id).jqGrid({ 
    url:"sg31b.php?id="+row_id+"&clt="+clt, 
    datatype: "json", 
    idPrefix:"sgd_",
    colNames: ['Id','Article','Désignation','Marque','Equivalence'],
    colModel: [ 
        {name:'e.id',index:'e.id',hidden:true}, 
        {name:'a.code',index:'a.code', width:100}, 
        {name:'a.descr',index:'a.descr', width:450}, 
        {name:'k.code',index:'k.code', width:80}, 
        {name:'e.equiv',index:'e.equiv',width:100}
    ], 
    pager: pager_id, 
    sortname: 'a.code', 
    hiddengrid:true,
    scroll:true,
    height:230,
    rowNum:10,
    autowidth:true,
    caption:'4 - EQUIVALENCE ARTICLES',
    gridComplete:function(){
        sortDataCol(this);
        if($("#"+subgrid_id+"_d").jqGrid('getGridParam','records') < $("#"+subgrid_id+"_d").jqGrid('getGridParam','rowNum')){
            $("#"+subgrid_id+"_d").jqGrid('setGridHeight','100%');
        }else{
            $("#"+subgrid_id+"_d").jqGrid('setGridParam',[{npage:1}]).jqGrid('setGridHeight',230);
        }
    }
}); 
$("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{search:false,add:false,edit:false,del:false});
$("#"+subgrid_table_id).jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
fullInputCss();

and the snapshot of result for less than 10 filtered rows : enter image description here

Now if I press Backspace in search field to obtain more rows, it seems that search doesn't fire because Firebug doesn't show any trace of request : enter image description here

If I delete added 'setGridHeight' lines in gridcomplete, all runs fine ! I think that one more time I'm wrong in my coding and understanding how jqGrid runs. Please could someone give me some way to solve this trouble ? Many thanks in advance. Have a nice day. JiheL

Community
  • 1
  • 1
JiheL
  • 167
  • 1
  • 5
  • 13
  • Try to remove `scroll:true` which you use. Virtual scrolling is nice feature in general, but the implementation in jqGrid contains many bugs and side effects. I don't recommend you to use `.` in the names and recommend you remove `index` property if it has the same value as `name` property. You should better use `$(this)` instead of `$("#"+subgrid_id+"_d")` in every callback. You can remove unneeded `class='scroll'` which you use (twice) and include `row_id` inside of `idPrefix` because one can open more as one subgrids for different rows in the same time. Currently you produce id duplicates. – Oleg Apr 18 '13 at 07:46
  • I recommend you to add "jquery" or "javascript" as additional tag of all your jqGrid questions to have better colors in the code which you posted. Alternatively you can include `` before the code (don't forget to include one empty line between the code and the comment). See [here](http://meta.stackexchange.com/a/81970/147495) for details. – Oleg Apr 18 '13 at 09:05
  • Just wanted to comment that I like the grid colors/styles in the screenshots :) – Losbear Jul 30 '13 at 13:49
  • Thank you for your comment, it is PSA theme from jquery-ui. – JiheL Jul 31 '13 at 05:08

1 Answers1

2

I suppose that the origin of the problem could be id duplicates on your page. Just now I wrote the answer on another your question where I described the problem detailed.

Current implementation of jqGrid (version 4.4.5) has problem in the code of filterToolbar which constructs id for input fields of the filter toolbar based on the following rule:

id="gs_" + cm.name

(see the line of code). It means that the id of the input field for the column a.code will be gs_a.code for every subgrid which you use. So you can have id duplicates.

So I recommend you redesign the naming concept in your code. You can use for example

name: row_id + "a_code", index: "a.code"

In the way the value like "a.code" will be still send during sorting of the grid, but you will have no id duplicates. In some scenarios (is you use repeatitems: false in jsonReader) you could need to use additional jsonmap attribute, but you don't need it in you current code.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798