Application of embedding Dynamic combobox in grid in extjs

Source: Internet
Author: User

Use combobox data Copy codeThe Code is as follows: comboDS = new Ext. data. JsonStore ({
Url: 'test. do ',
Fields :[{
Name: 'id'
},{
Name: 'display'
}]
});

Combobox Definition
The id in combobox must be included, and the value of combobox must be followed by the Data id.Copy codeThe Code is as follows: var comboBox = new Ext. form. ComboBox ({
Id: "cb", // required
TypeAhead: true,
ReadOnly: true,
AllowBlank: false,
AutoScroll: true,
SelectOnFocus: true,
EmptyText: 'select ...',
Store: comboDS,
ForceSelection: true,
TriggerAction: 'all ',
DisplayField: 'display ',
ValueField: 'id'
});

Grid definition:Copy codeThe Code is as follows: ds = new Ext. data. Store ({
Baseparams :{
Start: 0,
Limit: RowCount
},
Proxy: new Ext. data. HttpProxy ({
Url: 'test2. do'
}),
Reader: new Ext. data. JsonReader ({
Root: 'data ',
TotalProperty: 'totalcount'
},[{
Name: "bh"
},{
Name: "test"
}]);
});
Var cm = new Ext. grid. ColumnModel ([new Ext. grid. RowNumberer (),{
Header: "No ",
DataIndex: "bh"
},{
Header: "test ",
DataIndex: "test ",
Renderer: renderer,
Editor: comboBox
}]);
Grid = new Ext. grid. EditorGridPanel ({
Title: 'test ',
Ds: ds,
Cm: cm,
ClicksToEdit: 1,
ViewConfig :{
ForceFit: true
},
Bbar: new Ext. PagingToolbar ({
PageSize: RowCount,
Store: ds,
DisplayInfo: true,
DisplayMsg: 'display records from {0} to {1}, total records from {2 ',
EmptyMsg: "No record"
})
});

Renderer function of cm
This method is used to solve the problem. After the combobox is modified, it is displayed as id.Copy codeThe Code is as follows: function renderer (value, p, r ){
Var index = comboDS. find (Ext. getCmp ('cb '). valueField, value );
Var record = comboDS. getAt (index );
Var displayText = "";
If (record = null ){
DisplayText = value;
} Else {
DisplayText = record. data. display; // obtain the value of the display field in the dataset in record.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.