I am using the onCellClick function of Sigma Grid to allow the user to select from a grid and have a form updated with the selected information.
When I try to split the record that is returned from onCellClick (which returns the record associated with the grid row) I get an "Object doesn't support this property or method" pointing to the split line.
onCellClick : function(value, record, cell, row, colNO, rowNO, columnObj, grid){
var recordCurrent = record;
var recordSplit = recordCurrent.split(",");
alert("Participant is " + recordSplit[1]);
}
If I do an alert showing the unsplit record from the onCellClick event it shows the data I expect.
I am missing something obvious. Any direction you can provide will be appreciated.
-
1Check recordCurrent type if it's not string (so, it's not) you cannot split.enesunal– enesunal2012年06月22日 17:15:55 +00:00Commented Jun 22, 2012 at 17:15
-
Even, as Enes mentioned, if you can split it there's still a chance there won't be a value in the 2nd positionMike Robinson– Mike Robinson2012年06月22日 17:23:22 +00:00Commented Jun 22, 2012 at 17:23
2 Answers 2
The error you received "Object doesn't support this property or method" would suggest that you are attempting to call .split on something that doesn't have it (not a string).
You should check that your parameters are the types you expect before you work with them:
if (typeof record !== 'string') {
throw new Error('You must pass a string as the record to onCellClick!');
} else {
var recordCurrent = record;
var recordSplit = recordCurrent.split(",");
alert("Participant is " + recordSplit[1]);
}
Upon further investigation, Sigma grid documentation states that the type of the record parameter is Object or Array, not String.
2 Comments
You should perform two checks:
1) That there is actually a record
2) That the split record has more than one object in it
onCellClick : function(value, record, cell, row, colNO, rowNO, columnObj, grid){
if (record.length) {
var recordSplit = record.split(",");
if (recordSplit.length > 1) {
alert("Participant is " + recordSplit[1]);
}
}
}