Results 1 to 5 of 5

Thread: Component DataView, get records in listitems

  1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    29

    Default Component DataView, get records in listitems

    Hi,

    i try to build an list with useComponents activated.so far it works fine. The datarecord 'internal_state' which i will represent with togglefield does not contain "0" or "1" as value, but "on" or "off".
    So i tried to extend the apply method and check the current value with
    Code:
    this.getRecord().get('internal_state')
    . But in all cases the result ist null. Anybody with an approach?

    My list for devices look as follows:
    Code:
    Ext.define('HomeBox.view.DeviceListView', {
        extend: 'Ext.dataview.List',
        xtype: 'devicelist',
        requires: [
    		'Ext.plugin.PullRefresh',
            'HomeBox.view.DeviceListItemView'
        ],
    	config: {
    		useComponents: true,
    		defaultType: 'devicelistitem',
    		useHeaders: false,
    		plugins: [
    			{ xclass: 'Ext.plugin.PullRefresh' }
    		]
        }
    });
    and the item view:
    Code:
    Ext.define('HomeBox.view.DeviceListItemView', {
        extend: 'Ext.dataview.component.DataItem',
    	requires: [
    		'Ext.field.Toggle'
    	],
        xtype: 'devicelistitem',
        config: {
    		layout: 'hbox',
            styleHtmlContent: true,
            DeviceName: {
                flex: 1,
                tpl: '{.}',
                data: ''
            },
            DeviceToggle: {
                flex: 2
            },
    		dataMap: {
    			getDeviceName: {
    				setData: 'Name'
    			},
    			getDeviceToggle: {
    				setValue: 'internal_state'
    			},
    		}
        },
    	applyDeviceName: function(config) {
            return Ext.factory(config, Ext.Component, this.getDeviceName());
        },
    	updateDeviceName: function(newName, oldName) {
            if (newName) {
                this.add(newName);
            }
    
            if (oldName) {
                this.remove(oldName);
            }
        },
    	applyDeviceToggle: function(config) {
    		return Ext.factory(config, Ext.field.Toggle, this.getDeviceToggle());
        },
    	updateDeviceToggle: function(newOne, oldOne) {
            if (newOne) {
                this.add(newOne);
            }
    
            if (oldOne) {
                this.remove(oldOne);
            }
        },
    });

  2. #2
    Sencha User
    Join Date
    Feb 2008
    Posts
    29

    Default Additional informations needed

    Nobody with an idea? If additional informations are needed ... no prob.

    Thanks

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    29

    Default confused

    Logging this to console shows the object correctly. _record contains an data object with the needed data informations. Just the method getRecord does not work.

  4. #4
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    115

    Default updateRecord function

    there is this hidden gem function in DataItem that not many know.
    "updateRecord" which will pass the "record" of the data.
    you can try to do the settings inside that function.


    Code:
    Ext.define('HomeBox.view.DeviceListItemView', {
        extend: 'Ext.dataview.component.DataItem',
    	requires: [
    		'Ext.field.Toggle'
    	],
        xtype: 'devicelistitem',
        config: {
    		layout: 'hbox',
            styleHtmlContent: true,
            DeviceName: {
                flex: 1,
                tpl: '{.}',
                data: ''
            },
            DeviceToggle: {
                flex: 2
            },
    		dataMap: {
    			getDeviceName: {
    				setData: 'Name'
    			},
    			getDeviceToggle: {
    				setValue: 'internal_state'
    			},
    		}
        },
    	applyDeviceName: function(config) {
            return Ext.factory(config, Ext.Component, this.getDeviceName());
        },
    	updateDeviceName: function(newName, oldName) {
            if (newName) {
                this.add(newName);
            }
    
    
            if (oldName) {
                this.remove(oldName);
            }
        },
    	applyDeviceToggle: function(config) {
    		return Ext.factory(config, Ext.field.Toggle, this.getDeviceToggle());
        },
    	updateDeviceToggle: function(newOne, oldOne) {
            if (newOne) {
                this.add(newOne);
            }
    
    
            if (oldOne) {
                this.remove(oldOne);
            }
        },
        updateRecord: function (record) {
            this.callParent(arguments);
            if (record != null) {
                this.getDeviceToggle().setValue(record.data.internal_state);    //"internal_state" is the field for "DeviceToggle" and its data type is 1 or 0
            }
        }
    });

  5. #5
    Sencha User
    Join Date
    Feb 2008
    Posts
    29

    Default Thx

    @=NR= your tip pushed me foreward! Thx

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •