0

enter image description hereWe were using below code in jqgrid 4.3. Now I am upgrading to 4.13.6. The below code was working in 4.3, but in 4.13, it return false... Any help please...

var grid = $("#myGrid").jqGrid('getRowData');
$.each(grid, function(key, value) {
    selectedRow = key+1;
    var rowData = $("#myGrid").jqGrid('getLocalRow', selectedRow);
});

I am not using any id while filling my grid. datatype: json, rownumbers: true.

When I debug, I see the ID of each rows are 'jqg41', 'jqg42' etc... And sometimes it is 'jqg61', 'jqg62' etc... It is a random number which is appended after 'jqg'

some more code (but not completed code)

$grid.jqGrid({
                    datatype: 'json',
                    url: 'myUrl/byFileId.do?custId='+custId,
                    mtype: 'GET',
                    ajaxSubgridOptions: { async: false },
                    colNames:[ col1, col2 ...],
                    colModel:[    
                        . . .
                        . . .
                        . . .
                    ],  
                    headertitles:true,
                    rowNum:999,
                    rowList:[],
                    pager: '',
                    records: 1000,
                    pgbuttons : false,
                    viewrecords : false,
                    pgtext : null,
                    pginput : false,
                    gridview:true,
                    ignoreCase:true,
                    rownumbers:true,
                    sortname: 'invdate',
                    viewrecords: true,
                    sortorder: 'desc',
                    multiselect: true, 
                    caption: "Customer Search Result",
                    height: '100%',
                    editurl: 'clientArray',
                    autoencode: true,
                    loadonce: true,
                    multiselectWidth: 30,
                    width: rmtPageTitleWidth,
                    viewsortcols : [true,'vertical',true],
                    onSortCol: function (index, idxcol, sortorder) {
                        rowIdAndNoOfRowPair = [];
                        if (this.p.lastsort >= 0 && this.p.lastsort !== idxcol
                                && this.p.colModel[this.p.lastsort].sortable !== false) {
                            $(this.grid.headers[this.p.lastsort].el).find(">div.ui-jqgrid-sortable>span.s-ico").show();
                        }
                    },

enter image description here

SK.
  • 1,390
  • 2
  • 28
  • 59
  • Sorry, but the code, which you post is absolutely wrong.If `key` is the rowid, then `key+1` s not. What shell it do? Do you need to get the data of **selected** rows or all local data of the grid? Why you don't specify the rowid? Which data and which grid you use? By the way, I started my answer on your previous question with the suggestion to set `key: true` property in `customerId` column, which inform jqGrid to use the values from `customerId` column as rowids. **Your code still wrong any you should explain, what should it do.** – Oleg Feb 16 '17 at 07:33
  • I recommend you to read [the article](https://free-jqgrid.github.io/getting-started/index.html#the_first_grid), where I explain what is rowid. See [the picture](https://free-jqgrid.github.io/getting-started/index.html#grid-internal-div) and the explanation below. – Oleg Feb 16 '17 at 07:43
  • @Oleg: in jqgrid 4.3, the 'key' always gives me 0, but the id of the row starts from '1'. that is why I did "key+1'. Now to your second question, I can't make customer id as key=true, because I can have multiple customer of same id in the grid. What IS want: I want to go through each row (both select and non-selected) and get data, then I could apply logic with those data in javascript and then send to backend. now I am wondering why it is creating the id of row as 'jqg – SK. Feb 16 '17 at 12:41
  • I repeat, that what you explain is the automatic generation of generation of rowids **if the input data was wrong** and didn't contained and id information. You should never have any assumption about the algorithm of auto-generated ids. I still don't understand your description. You should never post such minimal fragment of code. I can only guess that you mean the grid with `datatype: "json"` and `loadonce: true` like in your previous question. You don't need to "go through each row". You can just use `$("#myGrid").jqGrid("getGridParam", "data")` to get the reference to all local data. – Oleg Feb 16 '17 at 13:05

1 Answers1

0

You can just use

var localData = $("#myGrid").jqGrid("getGridParam", "data");

to get all local data as an array. It's the reference to internal data of jqGrid.

UPDATED: If the grid is sorted or filtered locally and want to get the data from all rows in the same order, then you should get lastSelectedData parameter instead of data. You can force sorting the data locally after loading from the server by usage forceClientSorting: true parameter of jqGrid additionally to loadonce: true.

The demo https://jsfiddle.net/OlegKi/akv51mdq/ demonstrates lastSelectedData in case of local data, which has no id information. Another demo https://jsfiddle.net/OlegKi/Ljejoh21/ do the same with the data loaded from the server at once.

Oleg
  • 220,925
  • 34
  • 403
  • 798