PDA

View Full Version : Grid + checkcolumn + Json Store + int model - NaN



Frith
21 Oct 2013, 3:43 AM
Scenario:

Ext 4.2.1

I have a grid with a checkcolumn, a store, and a model. If the record in the database indicates that isSent = 1, then I want to catch this and prevent the user from unchecking the checkcolumn.

If the original value of isSent is 0, I want to allow the user to check the checkcolumn and mark as dirty.

One button at the bottom of the grid will collect all modified records and send them to the server.

The JSON returned from the server is as follows:



{
success:true,
recCount:"2",
code:0,
totalCount: 2,
data:[
{
"RowNumber":1,
"userId":1,
"surveyId":1,
"userSurname":"User",
"userFullname":"Test User",
"userEmail":"test.user@testcompany.com",
"isSent":0,
"distDate":null
},
{
"RowNumber":2,
"userId":2,
"surveyId":1,
"userSurname":"User",
"userFullname":"Another User",
"userEmail":"another.user@testcopmany.com",
"isSent":1,
"distDate":"2013-10-16 07:15:45"
}
]
}


The associated model is as follows:


Ext.define('BRM2.model.BRMSurveyDistributionModel', {
extend: 'Ext.data.Model',


idProperty: 'RowNumber',


fields: [
{
name: 'userId',
type: 'int'
},
{
name: 'isSent',
type: 'int'
},
{
name: 'surveyId',
type: 'int'
},
{
name: 'userSurname'
},
{
name: 'userFullname'
},
{
name: 'userEmail'
},
{
dateFormat: 'Y-m-d H:i:s',
name: 'distDate',
type: 'date'
},
{
name: 'RowNumber',
type: 'int'
}
]
});


See in the attached image that both userId and surveyId are correctly interpreted as integers but isSent comes back as NaN regardless of value.

This would therefore imply that the checkcolumn is modifying the value within the record...correct?

I would have imagined that the record would remain untouched but only interpreted by the column not modified by it.

evant
21 Oct 2013, 3:47 AM
When check/uncheck the box, it sets the value in the underlying model. See the processEvent method in the class.

Frith
21 Oct 2013, 3:57 AM
Don't you hate Mondays ???

I should be listening to beforecheckchange and modifying the record manually.

It would be better if the checkcolumn could be configured to set the value according to type instead of shoe-horning true or false.

evant
21 Oct 2013, 4:14 AM
You could always stick a custom convert method on your model:



convert: function(v) {
if (typeof v === 'boolean') {
return v ? 1 : 0;
} else {
return parseInt(v, 10);
}
}