Hello,
I am trying to determine the number of lines in my grid after using the command grid.loadXML(url1);
So far the command grid.getRowsNum() returns 0.
If I add the rows manually with grid.addRow(new_row,’’,new_index);, I get an accurate row count.
Is there anyway to return the number of rows after loading a grid with loadXML?
Thanks,
Craig
Please be sure that you call the command after data is really loaded ( loadXML is async. )
You may need to use onXLE event or second parameter of loadXML command to catch the moment when data really loaded.
I did the following to my grid
grid.attachEvent(‘onXLE’,resize_grid);
In the function resize_grid, I have the following commands
var num_rows_this_grid = grid.getRowsNum();
/* resize grids */
if(num_rows_this_grid > num_rows){
grid.setColWidth(index, newwidth);
} else {
grid.setColWidth(index, oldwidth);
}
This function resizes a column in the grid to make room for the scroll bar that appears after a certain number of lines are added.
In IE6, I get an error and the grid doesn’t initalize. There is no explanation for the error, and I can’t reproduce it in firefox 2 or firefox 3.
If I call the same function from a button on the form, I don’t get any errors.
Thanks,
Craig
Please be sure that newwidth and oldwidth values are pure numbers in any situation.
IE will throw an error if incorrect ( not numeric ) size will be provided ( while FF will just ignore it ) , so it very similar to your situation.
By the way, if you need to adjust grid , to prevent h-scroller, you can use enableAutoWidth mode or just set one of columns as flexible ( * as size )
The suggestion you sent was helpful but doesn’t quite display the grid like I want when there is a vertical scroll bar.
The command grid.setColWidth(index, newwidth); works some of the time. I’ve noticed that when loadXML takes a long time to complete, IE errors out when it tries to set the column width. When loadXML loads the grid quickly, grid.setColWidth(index, newwidth); works in IE.
The numbers I’m sending are whole numbers
I finally figured out where the error is coming from, line 118 in the dhtmlxgrid.js file
this.hdr.rows[0].cells[i].style.width=this.cellWidthPX[i]+"px"
windows is throwing an exception
Do you have some initial value size defined for each column ?
( grid.setInitWidths command with values for all columns )
Yes the inital column widths are set and the values are already loaded by loadXML
The error at mentioned line can occur only in two cases
a) initial width of column was not set
b) setColWidth was used with non-numeric value
If issue still occurs for you - please provide any kind of sample where problem can be reconstructed ( you can send such info directly to support@dhtmlx.com )
I have created a function called resizeGrids
/* name of the grid, number of rows, column index, old width, new width /
resizeGrids(mygrid_intervenant, 3, 3, 475, 459);
so if the number of rows in the mygrid_intervenant grid is greater than 3, reduce the size of the third column to make place for the scroll bar
Here is the function that resizes the grids
/ resize the grids if more than a certain number of rows are added /
function resizeGrids(grid, num_rows, index, oldwidth, newwidth){
var num_rows_this_grid = grid.getRowsNum();
//alert(num_rows_this_grid);
/ resize grids */
if(num_rows_this_grid > num_rows){
grid.setColWidth(index, newwidth);
} else {
grid.setColWidth(index, oldwidth);
}
}
This function is called by the onXLE event.
Errors only occur, if I resize the grid after data has been loaded by loadXML. The other problem is that the error on line 118 in the dhtmlxgrid.js file doesn’t always happen. If data is returned quickly by loadXML, IE doesn’t error out. I should also mention that there are two grids in the same form
The same code works correctly in local samples ( attached )
>> The other problem is that the error on line 118 in the dhtmlxgrid.js file doesn’t always happen. If data is returned quickly by loadXML, IE doesn’t error out.
It seems that it somehow caused by timing, please be sure that you have calling the correct grid instances from each onXLE handler.
Also, be sure that you are loading page by http:// like url, when page loaded directly from filesystem ( c:/some.html ) IE can change order of onXLE calls.
1234285510.zip (66 KB)