How to find the selected record in checkboxselection model

Date: Tuesday January 6, 2009
Posted in: xn--nqv032a89i.com edit

  • I have a checkboxselection model added in Gridpanel and i have put that checkboxselection model as first column in colum model of that grid.

    I m not able get the selected record (checkbox doesn't get checked for that particular row selected). on load of the grid at First Time.

    Below is the Code .

    I am also not able to get Record of that particular row, while checking the check box it returns first selected record (not that one, where event is fired)

    Here is My Code...


    Ext.onReady(function()
    {

    var xg2 = Ext.grid;
    witnessUserStrore = new Ext.data.GroupingStore({
    // load using HTTP
    url: 'XML/InjuredUsers.xml',
    // the return will be XML, so lets set up a reader
    reader: new Ext.data.XmlReader({
    // records will have an "Item" tag
    record: 'User ',
    id: 'ID',
    totalRecords: '@total'
    }, [
    // set up the fields mapping into the xml doc
    // The first needs mapping, the others are very basic




    {name: 'ID', mapping: 'User > ID'},


    {name: 'ID', type: 'int'},
    {name: 'UserName',type:'string'},
    {name: 'Email', type: 'string'}, // automatic date conversions
    {name: 'Phone', type:'string'},
    {name: 'EmpTypeDesc', type:'string'},
    {name: 'IsExist', type: 'bool'}

    // 'ID','UserName','Email','Phone','EmpTypeDesc','IsE xist'
    ])


    });

    var sm2 = new xg2.CheckboxSelectionModel(
    {

    dataIndex: 'IsExist'

    }
    );



    sm2.on('selectionchange',function(sm3)
    {


    var record= sm2.getSelected();

    if (!record.data[this.dataIndex])
    {


    var Name = record.get('UserName');
    var email = record.get('Email');
    var phone = record.get('Phone');
    var EmpType = record.get('EmpTypeDesc');
    var ID = record.get('ID');
    var bln = Incident.AddInjuredPerson(ID,Name,email,phone, GetEmpId(EmpType));




    }
    else
    {


    var userid = record.get('ID');
    var bln = Incident.DeleteInjuredPerson(userid);

    }



    });

    cm2 = new Ext.grid.ColumnModel([



    //checkColumn1,
    sm2,

    {
    id:'Name',
    header: 'Name',
    dataIndex: 'UserName',
    width: 300,
    sortable: true

    },
    {
    header: 'Email Address',
    dataIndex: 'Email',
    width: 300,
    sortable: true
    },

    {
    header: 'Phone',
    dataIndex: 'Phone',
    width: 170,
    sortable: true

    },

    {
    header: 'Emp Type',
    dataIndex: 'EmpTypeDesc',
    width: 245,
    sortable: true

    }


    ]);


    grid2 = new xg2.GridPanel({
    store: witnessUserStrore,
    cm:cm2,
    sm:sm2,



    width : GetPageWidth(),//parseInt((document.body.clientWidth)-82),
    height: GetPageHeight(),//160,
    collapsible: false,
    border:true,
    Collapse: false,
    frame:false,
    layout:'fit',
    title: 'Existing Users'//,
    });

    witnessUserStrore.load();




    });


  • It is exactly what documentation states: getSelected returns first selected record:
    http://extjs.com/deploy/dev/docs/?class=Ext.grid.RowSelectionModel&member=getSelected

    If you want all selected records then you need to call getSelections:
    http://extjs.com/deploy/dev/docs/?class=Ext.grid.RowSelectionModel&member=getSelections


  • Thanks for reply,

    I have 2 queries

    1. When first time grid is loaded check box is not checked. I am giving the 'IsExist' in the config part of the CheckBoxSelectionModel({dataIndex:'IsExist'}) ,

    How can I select the check box at load time (binding time) by giving the 'IsExist' value to true.


    2. Can I Get the Selected record where select event is fired (while clicking on the the checkbox), I means one record at a time.....


    Here is my Code........



    Ext.onReady(function()
    {

    var xg2 = Ext.grid;
    witnessUserStrore = new Ext.data.GroupingStore({
    // load using HTTP
    url: 'XML/InjuredUsers.xml',
    // the return will be XML, so lets set up a reader
    reader: new Ext.data.XmlReader({
    // records will have an "Item" tag
    record: 'User ',
    id: 'ID',
    totalRecords: '@total'
    }, [
    // set up the fields mapping into the xml doc
    // The first needs mapping, the others are very basic




    {name: 'ID', mapping: 'User > ID'},


    {name: 'ID', type: 'int'},
    {name: 'UserName',type:'string'},
    {name: 'Email', type: 'string'}, // automatic date conversions
    {name: 'Phone', type:'string'},
    {name: 'EmpTypeDesc', type:'string'},
    {name: 'IsExist', type: 'bool'}

    // 'ID','UserName','Email','Phone','EmpTypeDesc','IsE xist'
    ])


    });

    var sm2 = new xg2.CheckboxSelectionModel(
    {

    dataIndex: 'IsExist'

    }
    );



    sm2.on('selectionchange',function(sm3)
    {


    var record= sm2.getSelected();

    if (!record.data[this.dataIndex])
    {


    var Name = record.get('UserName');
    var email = record.get('Email');
    var phone = record.get('Phone');
    var EmpType = record.get('EmpTypeDesc');
    var ID = record.get('ID');
    var bln = Incident.AddInjuredPerson(ID,Name,email,phone, GetEmpId(EmpType));




    }
    else
    {


    var userid = record.get('ID');
    var bln = Incident.DeleteInjuredPerson(userid);

    }



    });

    cm2 = new Ext.grid.ColumnModel([



    //checkColumn1,
    sm2,

    {
    id:'Name',
    header: 'Name',
    dataIndex: 'UserName',
    width: 300,
    sortable: true

    },
    {
    header: 'Email Address',
    dataIndex: 'Email',
    width: 300,
    sortable: true
    },

    {
    header: 'Phone',
    dataIndex: 'Phone',
    width: 170,
    sortable: true

    },

    {
    header: 'Emp Type',
    dataIndex: 'EmpTypeDesc',
    width: 245,
    sortable: true

    }


    ]);


    grid2 = new xg2.GridPanel({
    store: witnessUserStrore,
    cm:cm2,
    sm:sm2,



    width : GetPageWidth(),//parseInt((document.body.clientWidth)-82),
    height: GetPageHeight(),//160,
    collapsible: false,
    border:true,
    Collapse: false,
    frame:false,
    layout:'fit',
    title: 'Existing Users'//,
    });

    witnessUserStrore.load();




    });







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about How to find the selected record in checkboxselection model , Please add it free.