I have a button that invokes the following and adds a new row to the grid in batch mode. The 6 position is a template field with a little button in it. The new row is missing the button when the code below is invoked. I cannot figure out how to add a row and ahve my template field load properly. Ideas?
var grid = $find("dgOther");
// Create array of cell values for all values that cannot be null.
var uniqueid = (new Date()).getTime().toString().substring(7, 14);
var row = new Array("", uniqueid, "", "1/1/1900", "", "", "", "", "", "");
grid.get_rows().add(row);
Hello baileyjames,
I'm glad you solved this issue. Thank you for sharing your code with the community.
If you have any other questions, please feel free to contact me.
Thanks so much for doing this Nikolay. Great sample. I identified the difference between your's and mine, thanks to you posting this.
#1 I have these 2 items set <ig:Activation Enabled="True" /> <ig:EditingCore BatchUpdating="True">
#2 I am using an input button so the page does NOT post back (too expensive to post, that is why I'm in batch mode). Try changing your button to this:
<input id="New" type="button" name="New" onclick="addRow();" style="margin-left: 10px; margin-top: 5px;" value="New" class="Button" />
...and the template column's button will not show up after you click on new. I'm thinking this is a bug or something that only renders on post. Bummer if so. Anyhow. I have a work-around a colleague found (below). It injects html into the cell's html element. Very clever.
function addRow() {
var uniqueid = (new Date()).getTime().toString().substring(7, 14); --filler pk for the grid that is unique.
var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();
for (var i = selectedRows.get_length(); i >= 0; i--) {
selectedRows.remove(selectedRows.getItem(i));
}
//select the row to add a button to
var newrow = grid.get_rows().get_row(grid._rows.get_length() - 1);
selectedRows.add(newrow);
var ICD9ModalButtonCell = newrow.get_cell(6); //identify the cell
var ICD9ModalButtonParentElement = ICD9ModalButtonCell.get_element(); //Identify the cell's html element
var onClickModalDialogICD9CellMethod = "ShowICDSearchModal('dgOther', '" + (grid._rows.get_length() - 1) + "', '6'); return false";
ICD9ModalButtonParentElement.innerHTML = '<input type="button" value="..." onclick="' + onClickModalDialogICD9CellMethod + '"class="Button" />'; //Inject the new html/java script so the user can click on it.
Hi baileyjames,
I am attaching a sample, replicating the scenario you have described. The WebDataGrid contains a templated field with a button inside. When adding new row client-side, the button is also created for this row.
Let me know if this helps.