I want add a link to a row cell after a new record is saved. I need to add the link after the record is saved because I need the “newly created server side row Id” that is returned in XML so I can pass it to the javascript function that the link will call.
So I know how to reference the cells but how can I guarantee that the save operation has completed so I can retrieve the new server side row id?
Note:
I already create javascript URLs from server side when grid is loading existing records. But I wanted to avoid doing full refresh of grid just to populate URLs for a new record.
So my sequence would go something like this.
1. Insert new record client (row key = (new Date()).valueOf())
2. Save new record and return new row id (example --> $xml .= “”
3. After save complete reference row key and use it as parameter in URL javascript function
ps.
The link is to open an upload window which allows users to upload files associated to a record. So this is why I need to save record first and use primary key in table as parameter.
You can use defineAction method or DataProcessor event to check if new row was inserted:
dp.defineAction(“insert”,insert_function)
function insert_function(node){
//node.getAttribute(“tid”) - new row id
}
dp.defineAction(“insert”,insert_function)
Why does this work? I use cellByIndex here.
function insert_function(node)
{
var rowId = node.getAttribute(“tid”);
var rowIndex = oGridWorkEstimate.getRowsNum() - 1;
oGrid.cellByIndex(rowIndex, 14).setValue(“Upload Video^javascript:uploadVideo(” + rowId + “)^_self”);
}
But this does not work? I use cellById here. I get the following error…Line: 973
Error: ‘_childIndexes’ is null or not an object. I am able to get rowId in both cases but I cannot use the rowId with cellbyId function.
function insert_function(node)
{
var rowId = node.getAttribute(“tid”);
oGrid.cellById(rowId, 14).setValue(“Upload Video^javascript:uploadVideo(” + rowId + “)^_self”);
}
small typo aboe where oGridWorkEstimate.getRowsNum() - 1; should use oGrid.
Ok, I figured it out. Its seems I need to use the “client side row id” when using cellById…even after saving.
function insert_function()
{
var rowIdDB = node.getAttribute(“tid”);
var rowIdClient = node.getAttribute(“sid”);
oGrid.cellById(rowIdClient, 14).setValue(“Upload Video^javascript:uploadVideo(” + rowIdDB + “)^_self”);
}
actually that does not work either. Still only cellByIndex works.
Sorry. Yes my final solution does indeed work. cellById works when using the original client row Id after a save. Thanks.
I need to use the “client side row id” when using cellById…even after saving.
The order of actions
- insert callback received
- code attached by defineAction called
- native insert related code called ( id of client side record changed )
so, code inside defineAction handler need to use “sid” attribute , because it called before id of row changed to new one
Also, be sure to add the next line
function insert_function(){
var rowIdDB = node.getAttribute(“tid”);
var rowIdClient = node.getAttribute(“sid”);
oGrid.cellById(rowIdClient, 14).setValue(“Upload Video^javascript:uploadVideo(” + rowIdDB + “)^_self”);
return true;
}
without it, your custom code blocks default after-insert processing
Thank you. Works great now.