Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Valerie on Aug 21, 2008 09:11
open dhtmlx forum
Populate column values after adding new row

Currently i have a grid with 4 columns and the first column contains a checkbox. After adding a new row, how do i add a checkbox or input tag to that column? And how do i add a new row as the first row of the grid? Thanks for the help in advance!
Answer posted by Support on Aug 21, 2008 09:22
If you have defined column as checkbox
     grid.setColTypes("ch,ed,ed,ed");
The related column in new row will be a checkbox. 

To add row at necessary position 3rd parameter of addRow can be used
   grid.addRow(id,values,0); // add as first row in grid
Answer posted on Aug 21, 2008 19:52
The "values" variable is an array of values? I want to enter empty strings into all the columns except for the checkbox column. In the checkbox column, the checkboxes were inserted by <input> tags in my Java file by using CData method. How do i enter html tags into the checkbox column? How can the "values" variable know where to place what?
Answer posted by Support on Aug 22, 2008 02:09
>>The "values" variable is an array of values? 
It can be a comma separated list or an array. 
grid.addRow(id,"1,2,3")
or 
grid.addRow(id,["1","2","3"])

>>How can the "values" variable know where to place what?
The data mapped to related column , first element of array to first column of grid, second to second , etc. If you need to enter data in first column you can define only first element of array. 

grid.addRow(id,["<input type='checkbox' />"]);

By the way , if you are using "ch" column type, you need not define any HTML tags, grid will automatically render checkbox for such cells, the 0 as value will result in unchecked checkbox, 1 as value - checked checkbox

Answer posted by Valerie on Aug 24, 2008 10:11
I am using my own checkbox, but if i use the inbuilt "ch" is there anyway i can rename the checkbox name and id? As i would need to do some validation with it. Btw, the html code worked for the addRow.
Answer posted by Support on Aug 25, 2008 01:56
>>but if i use the inbuilt "ch" is there anyway i can rename the checkbox name and id
The checkboxes created for "ch" column are nameless and can be accessed only through grid's API
Answer posted by Valerie on Aug 25, 2008 05:21
Thank you, you have been very helpful. I think i will have to use my own <input> tag for the checkboxes.