0

I am working on a task where I need to update entire row data in jqgrid.

Here is a sample fiddler: https://jsfiddle.net/99x50s2s/47/

In the above fiddler, please update a row and then try to scroll to the right.

Code:

var $thisGrid = jQuery("#sg1");
$thisGrid.jqGrid({
    datatype: "local",
    gridview: true,
    loadonce: true,
    shrinkToFit: false,
    autoencode: true,
    height: 'auto',
    width: 400,
    viewrecords: true,
    sortorder: "desc",
    scrollrows: true,
    loadui: 'disable',
    colNames:["", 'Inv No', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {
            name: "Symbol", index: "Symbol", width: 70, align: 'center', frozen: true,
                formatter: function (cellValue, options, rowObject) {
                    return '<button class="btn btn-info btn-xs update" type="button" title="Update" >' +
                            '<span class="glyphicon glyphicon-remove-circle"></span> Update</button>';
                }
            },
        {name:'id',width:60, sorttype:"int"},   
        {name:'name', width:100},
        {name:'amount', width:80, align:"right",sorttype:"float"},
        {name:'tax', width:80, align:"right",sorttype:"float"},     
        {name:'total', width:80,align:"right",sorttype:"float"},        
        {name:'note', width:150}        
    ],
    caption: "Test Data",
        onCellSelect: function (rowid,
        iCol,
        cellcontent,
        e) {
            if (iCol == 0) {
                var newdata = [
                {id:"1",name:"new test1 name for testing purpose",note:"new note1",amount:"500.00",tax:"50.00",total:"510.00"},    
                ];
                $thisGrid.jqGrid('setRowData', rowid, newdata[0]);
            }               
        }
}).jqGrid('setFrozenColumns');

var mydata = [
    {id:"1",name:"test1",note:"note1",amount:"200.00",tax:"10.00",total:"210.00"},
    {id:"2",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
    {id:"3",name:"test3",note:"note3",amount:"400.00",tax:"25.00",total:"360.00"},
    {id:"4",name:"test4",note:"note4",amount:"500.00",tax:"60.00",total:"350.00"},
    {id:"5",name:"test5",note:"note5",amount:"600.00",tax:"70.00",total:"340.00"}
        ];

for(var i=0;i<=mydata.length;i++)
    $thisGrid.jqGrid('addRowData',i+1,mydata[i]);

enter image description here

I am wondering how I can fix this behavior? Any help is appreciated.

Note:

jqGrid version: 4.6.0 Applied: Frozen column and cell text wrap.

EDIT:

snapshot taken from the fiddler with solution:

enter image description here

JGV
  • 5,037
  • 9
  • 50
  • 94

1 Answers1

0

I wrote you already in the past that the version 4.6.0 don't support editing of grids with frozen columns.

To make the code working one have to do many things after every change of the grid content. One have to adjust position of frozen divs and to set explicitly the height and the width of every row in the frozen div. You can find examples from the code which one have to use here and here.

There are exist more easy solution now. If you just replace the version jqGrid 4.6 to the current one code of free jqGrid from github

<link href="https://rawgit.com/free-jqgrid/jqGrid/master/css/ui.jqgrid.css" rel="stylesheet"/>
<script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/i18n/grid.locale-en.js"></script>
<script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>

then your code start working as expected: https://jsfiddle.net/OlegKi/99x50s2s/48/

So you can either to do many things yourself or to get the code which already do this.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • earlier I was trying to edit only the frozen cell but now, the entire row. But, your answer make sense... – JGV May 30 '15 at 16:49
  • I see a minor issue in the fiddler you've provided. Try to squeeze a column and see the frozen column behavior... it looks like duplicate buttons are appearing in the frozen column. – JGV Jun 03 '15 at 20:48
  • @VimalanJayaGanesh: Sorry, but probably I don't understand what you mean. I can't reproduce any problem. Moreover it's recommended to make the columns not resizable if the content of the columns is fixed (like the width of buttons). So it could be good to add `resizable: false` to the first column. If some problem do exist, please describe more exactly the test case. – Oleg Jun 03 '15 at 20:54
  • Oleg, I have updated the question with the snapshot and the steps involved in reproducing the issue. – JGV Jun 03 '15 at 21:01
  • 1
    @VimalanJayaGanesh: Thank you for the bug report. I removed old unneeded event handler used on resizing and the new handler will be used now (see [the fix](https://github.com/free-jqgrid/jqGrid)). Please retry the same demo. It uses the source from GitHub and it works now correctly. – Oleg Jun 03 '15 at 21:15
  • @VimalanJayaGanesh: You are welcome! It's easy to fix a bug it there are exist the demo and the test case. Thanks you too. – Oleg Jun 03 '15 at 21:20