chanjianyi
chanjianyi

Reputation: 615

How can I get the id in Extjs checkcolumn?

Im tiro in Extjs.

That is my model:

Ext.define('CatModel', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
     fields: [{
        name: "name",
        convert: undefined
    }, {
        name: "id",
        convert: undefined
    }]
}); 

store:

var store = Ext.create('Ext.data.TreeStore', {
    model:'CatModel',
    root: {
        expanded: true
    },
    proxy: {
        type: 'ajax',
        reader: 'json',
        url: 'item_access.jsp?fullpage=true&show_cat=1'
    }
});

and treePanel:

var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'tree-panel',
    title: 'Sample Layouts',
    region:'north',
    split: true,
    height: 560,
    minSize: 150,
    rootVisible: false,
    autoScroll: true,
    store: store,
    columns: [
        {
            xtype: 'treecolumn',
            text: 'name',
            flex: 2.5,
            sortable: true,
            dataIndex: 'name'
        },
        {
            text: 'id',//I want to get this id
            flex: 1,
            dataIndex: 'id',
            sortable: true
        }
        , {
            xtype: 'checkcolumn',
            text: 'Done',
            dataIndex: 'done',
            width: 55,
            stopSelection: false,
            menuDisabled: true,
            listeners:{
                checkchange:function(cc,ix,isChecked){
                    //alert(isChecked);
                    //I want to get this row id in here 
                }
            }
        }]
});

In checkchange function there are three parameter one unknown,two is index, and three is check status ...

So how can I get the the same row id where I check the checkbox??

Can I find that id number by checkbox row index??

Upvotes: 2

Views: 3797

Answers (1)

matt
matt

Reputation: 4047

You should be able to get the record from the TreeView with the row index, and then get the id property from it:

listeners:{
    checkchange: function(col, idx, isChecked) {
        var view = treePanel.getView(),
            record = view.getRecord(view.getNode(idx));

        console.log(record.get('id'));
    }
}

Upvotes: 8

Related Questions