hwilliams
hwilliams

Reputation: 11

java script split error

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.

Upvotes: 1

Views: 5837

Answers (2)

jbabey
jbabey

Reputation: 46647

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.

Upvotes: 1

alecananian
alecananian

Reputation: 1152

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]);
        }
    }
}

Upvotes: 0

Related Questions