Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
addXmlData local with pager rowid bug
12/04/2012
23:06
Avatar
tedt3
Member
Members
Forum Posts: 4
Member Since:
12/04/2012
sp_UserOfflineSmall Offline

Only the first group of rows until the grids rowNum parameter are assigned the correct rowid.  Everything that follows has a rowid that is 1 higher than it should.

So if for example I have 50 rows and I have a rowNum of 25 to display only 25 rows on the grid at a time I can only call getLocalRow() for the first 24 rows.  Once I call getLocalRow passing 25 or above I am returned the row after the row I am requesting.

Looking at the source for addXmlData

In the first loop getId is called like this: rid = getId(xmlr,br+j);

In the second loop that loads all data after rowNum getId is called like this: rid= getId(xmlr, ir);

Changing this line to rid = getId(xmlr, br + ir);  appears to fix the issue

17/04/2012
14:19
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Humm, actally this is partial true. This means that something is wrong with your response or configuration.

That is the:  rid = getId(xmlr, br + ir); - i.e br+ir is called only in case the grid can not find the cell or you maybe forgot to set the index property in colModel or you forgot to set key:true propery for the column which should act as id.

Just look for getId and see the k parameter

1. getId = function( trow, k) {return $(idn,trow).text() || k;};

or

2.getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;}; } 

or

3. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

17/04/2012
17:01
Avatar
tedt3
Member
Members
Forum Posts: 4
Member Since:
12/04/2012
sp_UserOfflineSmall Offline

No I'm pretty sure it's not my code that is causing this. I've created a small example that does the same thing.

Here is a sample xml file

<!–

<?xml version="1.0″ encoding="utf-8″?>

<result>

<rows>

<row>

<cell>row1</cell>

</row>

<row>

<cell>row2</cell>

</row>

<row>

<cell>row3</cell>

</row>

<row>

<cell>row4</cell>

</row>

<row>

<cell>row5</cell>

</row>

</row>

</rows>

</result>

–>

And here is a sample html page. Notice I have rowNum set to 2 in my grid so it only shows 2 rows at a time.

<!–

<html>

<link rel="stylesheet" type="text/css" href="../jqgrid/css/ui.jqgrid.css" />

<link rel="stylesheet" type="text/css" href="../jquery_ui/css/ui-lightness/jquery-ui-1.8.17.custom.css" />

<script type="text/javascript" src="../jquery_ui/js/jquery-1.7.1.min.js"></script>

<script type="text/javascript" src="../jquery_ui/js/jquery-ui-1.8.17.custom.min.js"></script>

<script type="text/javascript" src="../jqgrid/js/i18n/grid.locale-en.js"></script>

<script type="text/javascript"src="../jqgrid/js/jquery.jqGrid.min.js"></script>

<script type="text/javascript">

function fillGrid()

{

var colModelArray = [{name:'col1', index:'col1', sortype:'string', editable:false}];

var colNamesArray = ['Column1'];

jQuery("#grid").jqGrid({

datatype: "xml",

url: "data.xml",

colNames: colNamesArray,

colModel: colModelArray,

height: 'auto',

autowidth: true,

rowNum: 2,

pager: '#grid_pager',

rowList:[2, 5],

viewrecords: true,

loadonce: true,

processing: true

});

jQuery("#grid").navGrid('#grid_pager',{edit:false,add:false,del:false,search:true,refresh:false});

}

function checkRows()

{

var TotalRows = $("#grid").getGridParam("records");

var debugStr = "<table><tr><th>Row</th><th>Data</th></tr>";

for (var i = 1; i <= TotalRows; i++)

{

var rowObj = $('#grid').getLocalRow(i);

debugStr = debugStr + "<tr><td>" + i + "</td><td>" + rowObj.col1 + "</td></tr>";

}

debugStr = debugStr + "</table>";

$('#grid_debug').html(debugStr);

}

$(document).ready(function(){

fillGrid();

});

</script>

<body>

<div style="width: 600px;">

<div style="float: left; width: 600px;">

<table id="grid"></table>

<div id="grid_pager"></div>

&nbsp;

</div>

<div style="float: left; width: 600px;">

<div id="grid_debug">

</div>

</div>

<div style="float: left; width: 600px;">

<input type="button" onClick="checkRows();" value="Check Grid Rows">

</div>

</div>

</body>

</html>

–>

After the page loads if you hit the Check Grid Rows Button you will see the following:

Row Data

1 row1

2 row3

3 row4

4 row5

5 undefined

Notice how Row 2 doesn't show row2 instead it shows row3. Now if I keep all the code above identical except change rowNum parameter of the grid to 3 I get this:

Row Data

1 row1

2 row2

3 row4

4 row5

5 undefined

17/04/2012
21:06
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Try with this loop instead:

...

for (var i = 0; i < TotalRows; i++)

{

var rowObj = $('#grid').getLocalRow(i);

debugStr = debugStr + "<tr><td>" + i + "</td><td>" + rowObj.col1 + "</td></tr>";

}

..

The response instread is not correct - there are miised tags for records page and etc.

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

17/04/2012
21:34
Avatar
tedt3
Member
Members
Forum Posts: 4
Member Since:
12/04/2012
sp_UserOfflineSmall Offline

I've already tried the 0 based vs 1 based loop.  Doing what you suggest results in this.

Row Data
0 undefined
1 row1
2 row2
3 row4
4 row5

rowID 0 is invalid so no data row returned

rowIDs 1 and 2 return the correct rows

rowID 3 which is equal to the rowNum grid paramter should return a row with the value "row3" instead it returs the next row.

All rows after this return the row after it instead of the correct row.

18/04/2012
00:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

As I say the xml is not suitable for jqGrid.

You should configure the id row - i.e. thel the grid which is the id from thew response.

Please read here before to make any conclusions:

http://www.trirand.com/jqgridw.....a#xml_data

The easy way is to use this definition:

var colModelArray = [{name:'col1', index:'col1', sortype:'string', editable:false, key:true}];

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

18/04/2012
00:22
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Or set the id in the response:

<result>

<rows>

<row id='1'>

<cell>row1</cell>

</row>

<row id='2'>

<cell>row2</cell>

</row>

<row id='3'>

<cell>row3</cell>

</row>

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

18/04/2012
06:01
Avatar
tedt3
Member
Members
Forum Posts: 4
Member Since:
12/04/2012
sp_UserOfflineSmall Offline

Thanks for the suggestion to assign the row id using the id attribute for the row tag.  While that works correctly there is still a bug as I have stated in the previous posts.

Here is the getId function used in addXmlData.

getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};

 it works fine when it has the id attribute in the row tag.  But if the attribute is not used (and it's not used in any of the examples from the link you provided) it just returns k which was passed in.

Then in the addXmlData function there are 2 loops.

The first loop whilch runs until it breaks out when the rowNum parameter to the jqGrid function is reached calls getId like this

    rid = getId(xmlr,br+j);  The br in my case  is 1 and not random because scroll grid parameter is set to false. so 1 is added to each rowid.

var br=ts.p.scroll?$.jgrid.randId():1,altr;

 

Then since I am loading the entire grid at once the second loop processes the rest of the rows that aren't currently displayed.  But it calls getId like this

rid = getId(xmlr,ir); 

It no longer is adding br so rid is set to the current row.

 

That is a problem because the rows read in the first loop are using a 1 based counter because of the +br and the rows read in the second loop are using a 0 based counter. 


18/04/2012
12:09
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
58 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information