Hello!
How can I set the first row id from 0 to 1?
I need sync data with mysql. MySql defaultlyuse 1 to first id.
Thanks for help!
Regards,
Bela
Hello!
How can I set the first row id from 0 to 1?
I need sync data with mysql. MySql defaultlyuse 1 to first id.
Thanks for help!
Regards,
Bela
how are you generating/creating your xml. I mean are using grid’s connector functionality or have your own custom code for it?
Using your custom code(below one is java) while generating xml you can try the following:-
int i=0;
while(i<endOfRecord){
xml = "<row id=\"" + (i + 1) + "\">\n";
//create your rows
xml = xml + "</row>\n";
i++;
}
}
Another way is to call a custom javascript method after the page with grid data is loaded:-
mygrid.forEachRow(function(id) {
mygrid.changeRowId(id, id + 1);
});
I hope this helps.
-Sam
Thank you Sam!
My grid looks:
var ar = <?php echo $list;?>
var mygrid;
function doInitGrid(){
mygrid = new dhtmlXGridObject(“dhtmlxGridSellSumList”);
mygrid.setImagePath(“images/dhtmlx/”)
mygrid.setHeader(“Menny.,Megnevezés,Bruttó Ár(Ft)”);
mygrid.setInitWidths(“75,150,130”);
mygrid.setColAlign(“center,center,right”);
mygrid.setColTypes(“ro,ro,ro”);
mygrid.enableAlterCss(“even_row”);
mygrid.init();
mygrid.setStyle(“background-color:rgb(255,205,25);font-size:18px;font-weight:bold”,“color:white;font-size:18px;padding-top:7px;padding-bottom:7px;padding-right:5px;”,"",“background-color:rgb(225,225,225);color:red;”);
mygrid.parse(ar,“jsarray”);
}
doInitGrid();
mygrid.forEachRow(function(id) {
mygrid.changeRowId(id, id + 1);
});
mygrid.selectRow(mygrid.getRowsNum(),"","",true);
But this doesn’t select the last row just this way:
mygrid.selectRow(mygrid.getRowsNum()-1,"","",true);
I am not sure that I understand what are you trying to achieve here with
“mygrid.selectRow(mygrid.getRowsNum()-1,”","",true);"
If i assume that you are trying to do something if user selects a row, you can use an event as below. Please find the explanation here:- http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:event_onrowselect
grid.attachEvent(“onRowSelect”, function(id,ind){});
I think that you may have read the explanation of grid’s row methods here:- http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:rows_manipulation#selecting_rows
I believe explaining what you want to do will help to provide a specific solution for your issue.
Thanks,
-Sam
I would like to select the last row and scroll it into view.
And I need the rows id start from 1 not from 0.
Please try the following:-
In your doInitGrid(); method put the following code after parse method line :-
function doInitGrid(){
...
...
mygrid.parse(ar,"jsarray");
mygrid.attachEvent("onXLE", function() {
doAfterGridLoad();
});
}
In doAfterGridLoad() function:-
function doAfterGridLoad(){
var lastRowId = null;
mygrid.forEachRow(function(id) {
lastRowId = id;
mygrid.changeRowId(id, id + 1);//This will increment all the row id's by 1.
});
mygrid.showRow(lastRowId);//will scroll row to the visible area
}
I hope this helps.
Thanks,
-Sam
Please try with the following code in doAfterGridLoad() method:-
function doAfterGridLoad(){
mygrid.forEachRow(function(id) {
mygrid.changeRowId(id, id + 1);//This will increment all the row id's by 1.
});
mygrid.selectCell(mygrid.getRowsNum()-1,1,false,false,true);
mygrid.setCellExcellType(mygrid.getRowsNum(),1,"ed");
//this will change the row's 2nd cell type to enable edit mode
mygrid.editCell();
}
I try to what you suggested me but the attached event didn’t run
…
mygrid.parse(ar,“jsarray”);
mygrid.attachEvent(“onXLE”, function() {
doAfterGridLoad();
});
}
doInitGrid();
function doAfterGridLoad(){
var lastRowId = null;
mygrid.forEachRow(function(id) {
alert(id);
lastRowId = id;
mygrid.changeRowId(id, id + 1);//This will increment all the row id’s by 1.
});
mygrid.showRow(lastRowId);//will scroll row to the visible area
}
But No alert and no selection
I ran the function manually and the ressult you can see on the attached picture
The lastrow didn’t selected and if i click any row it is always in a selected state
For showing the last row you may try to use the following function:
var ind=mygrid.getRowsNum()-1
mygrid.showRow(mygrid.getRowId(ind));
Thank you but before this I need to change the id order starts from 1
mygrid.loadXML("grid.xml",function(){
mygrid.forEachRow(function(id){
var newId=mygrid.getRowIndex(id)+1
mygrid.changeRowId(id,newId);
});
});
or
mygrid.loadXML("grid.xml",function(){
mygrid.forEachRow(function(id){
var ind=mygrid.getRowIndex(id)
mygrid.setRowId(ind,ind+1);
});
});