What is the easiest way to display a NULL value as an empty string instead of the "null" string in an ExtJS grid?

I have a server-side script (PHP) that returns JSON data to populate an ExtJS grid.

This data comes from a MySQL query containing multiple NULL values.

When PHP encodes it into JSON notation, it keeps NULL intact:

{"id":"33","name":"Test1","url":null,"cls":"x-tree-noicon","expanded":true}

But ... when this data is displayed in the ExtJS grid, the string " null " is displayed in place of the NULL value .

I do not want it to display " null ". I just want it to be empty (empty string).

What is the easiest way to achieve this?

Thank.

+3
source share
5 answers

I'm not sure the easiest one, but the first thing that comes to my mind is to create a custom one renderer. You can use something like this:

function render(value){
    if(value === null){
        value = '';
    }
    return value;
}
+2
source

WoLpH's answer is correct. My own question was somehow "wrong" ... :-)

In fact, I am dealing with treegrid (Ext.ux.tree.TreeGrid), and not a common ExtJS grid (Ext.grid.GridPanel).

The columns of treegrid are not Ext.grid.Column , like a common grid. They have Ext.list.Column .

This means that the rendering configuration parameter is not applied (it exists and works on Ext.grid.Column, but not on Ext.list.Column).

Ext.list.Column, tpl, Ext.XTemplate.

treegrid, , :

tpl: '<tpl if="url === null"></tpl><tpl if="url !== null">{url}</tpl>'

NULL null treegrid!


: WoLpH, . , / , . , . .

+2

- . NULL , .

+2

Ext.data.Model? Ext.data, Ext.data.Store JSON ...

: 'auto'

:

Ext.define('testModel', {
        extend  : 'Ext.data.Model',
        fields  :[
                     {name: 'Id', type: 'int'},
                     {name: 'name', type: 'string'},
                     {name: 'url', type: 'auto'},
                     {name: 'cls', type: 'string'},                     
                     {name: 'expanded', type: 'boolean'}
                  ]     
    });


var testStore = Ext.create('Ext.data.Store', {
                         model  : 'testModel',
                         proxy  : {
                                      type   : 'memory',
                                      reader : {type:'json'}
                                  }
                });

testStore, .

+2

ExtJS 3.4 useNull, ( ).

http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.data.Field-cfg-useNull

() Number ( int, float). , null , useNull , 0.

: false

.

{
    name: 'myId',
    type: 'int',
    useNull: true
},
+1
source

Source: https://habr.com/ru/post/1759443/


All Articles