ExtJS 4, adjust the value of the Boolean column for Ext.grid.Panel

Good day, I have a grid with a boolean column:

var grid = Ext.create('Ext.grid.Panel', { ... columns: [{ dataIndex: 'visibleForUser', text: 'Visible', editor: { xtype: 'checkboxfield', inputValue: 1 // <-- this option has no effect } }, ... 

The mesh grid is removed through the JSON proxy. When I save or update a string, the resulting JSON looks like this:

 {... visibleForUser: false, ... } 

As you can see, ExtJS serializes the flag value as true or false JSON. I need to configure this and serialize, say 1 and 0 , any suggestion how to do this? Thanks.

+4
source share
3 answers

You can try to override getValue

 Ext.define('Ext.form.field.Checkbox', { override : 'Ext.form.field.Checkbox', getValue: function () { return this.checked ? 1 : 0; } }); 
+1
source

I just changed my checkboxes in the system to always act / respond to 0 and 1 :

 Ext.onReady(function(){ // Set the values of checkboxes to 1 (true) or 0 (false), // so they work with json and SQL BOOL field type Ext.override(Ext.form.field.Checkbox, { inputValue: '1', uncheckedValue: '0' }); }); 

But you can just add these configs for each flag.

+5
source

Ext JS 4.1.1 has a new serialize configuration in the write fields. When the writer prepares the record data, the serialize method is called to create the output value instead of just accepting the actual field value. So you can do something like this:

 fields: [{ name: "visibleForUser", type: "boolean", serialize: function(v){ return v ? 1 : 0; } /* other fields */ }] 

I try to avoid overriding the default behavior of components when possible. As I mentioned, this only works in 4.1.1 (it was introduced in 4.1.0, but I believe that it was broken). Therefore, if you are using an earlier version, one of the other answers will suit you better.

+3
source

All Articles