Home Web Front-end JS Tutorial EXTJS Notepad When CompositeField meets RowEditor_extjs

EXTJS Notepad When CompositeField meets RowEditor_extjs

May 16, 2016 pm 06:04 PM

The reason is that the customer has many types of materials, as many as a thousand. If only one Combobox is used, it will be difficult to quickly find a material in actual use. Therefore, I use two comboboxes containing material classification and material brand. Form a cascade filter. The problem lies precisely here. If you use multiple controls in a roweditor field, you must handle the initialization and Change event of each control. I haven't found anyone on the Internet with a good solution yet. After 3 days of debugging, I finally solved the problem and posted my code:

Copy the code The code is as follows:

var editor=new Ext.ux.grid.RowEditor({
saveText: 'OK',
cancelText: "Give up",
commitChangesText: 'Please confirm or give up the changes' ,
errorText: 'Error'
});
//When canceling, delete empty records based on whether the value of the key field is empty
editor.on("canceledit",function (editor,pressed)
{
if(pressed && editor.record.get("materialid")==0)
{
store.remove(editor.record);
}
},this);
/*
afterstart This event is added by myself, because if you want to initialize your own control in the beforeedit event, it is impossible, because during beforeedit, the roweditor control is still There is no rendering, so I added the afterstart event, which is called immediately after the roweditor is displayed, so it can be initialized here.
It should be noted that the customized composite control
editor.items.items[0] is accessed by traversing through the roweditor control. It is not that I overwrote it here, but that the items of the roweditor control are not a collection. It is an object. I also spent some time here. Finally, I found that
editor.items.items[0] is the compositefield component through firebug output editor object. Through the items collection of this component, I can use the standard Access its subcomponents in the form. Next, you can initialize
Because the data of the last combobox is loaded through the first two combobox cascade selections, so load its data here for initialization, but pay attention , I executed it in the callback, because the load action of jsonstore is asynchronous, so the value must be initialized with setValue through the callback of the callback event after the data is loaded successfully
*/
editor.on ("afterstart",function(editor,rowIndex)
{
var record=store.getAt(rowIndex);
editor.items.items[0].items.items[0].setValue(record .get("setid"));
editor.items.items[0].items.items[1].setValue(record.get("category"));
var t_store=editor.items. items[0].items.items[2].getStore();
t_store.load({
params:{category:record.get("category"),setid:record.get("setid" )},
callback:function(r,options,success){
if (success)
editor.items.items[0].items.items[2].setValue(record.get(" materialid"));
}
});
},this);
/*
validateedit event is executed when confirm is pressed and is used to verify each control in roweditor Value, here, I perform a custom validation action, because I don’t want users to be able to add duplicate materials, so I traverse the jsonstore and compare the material value of each record with the material value selected by the user. If found already exists, prompt the user not to add it repeatedly
*/
editor.on("validateedit",function(editor,obj,record,rowIndex){
var materialid=editor.items.items[0] .items.items[2].getValue();
var exist=false;
Ext.each(store.getRange(),function(o,i){
if(o!=record&&o. get("materialid")==materialid)
{
exist=true;
return(false);
}
});
if(exist)
{
Ext.MessageBox.alert("System prompt", "Do not add repeatedly");
store.remove(record);
}
return(!exist);
}, this);
/*
afterEdit is executed after passing verification. The most important action here is to assign values ​​to certain attributes of the record being edited. The reason is that due to the use of compsitefield, roweditor cannot assign the selected To assign the correct attribute of the record, we need to manually assign the user's selection to the corresponding field. The materialid is the material number selected by the user, and the model corresponds to the model of the material
Why do we need to assign model? Because the model is the value of the column, if it is not assigned, the display will be empty
*/
editor.on("afteredit",function(editor,obj,record,rowIndex){
record.set ("materialid",editor.items.items[0].items.items[2].getValue());
record.set("model",editor.items.items[0].items.items[ 2].getRawValue());
},this);

The above is the definition of roweditor and the processing of events. Next, insert roweditor as a plug-in into gridpanel
Copy code The code is as follows:

{
xtype:"grid",
title:"Product BOM",
layout:"fit",
store:store,
enableDragDrop: false,
border: false,
frame:false,
autoScroll:true ,plugins:[editor],
sm:sm,
height:340,
clicksToEdit:2,
autoWidth: true,
viewConfig:{forceFit:true,autoFill:true,markDirty:false}
}

Next, let’s take a look at the column definitions of gridpanel. Here, you You can see how composite is used
Copy the code The code is as follows:

columns: [{

header: "Material name/model",
dataIndex: "model",
width: 200,
menuDisabled: true,
editor:
{
//Definition editor
xtype: "compositefield",
name: "compositefield",
items:[
{
xtype: "combo ",
mode: "local",
name: "sets",
width:80,
fieldLabel: "Applicable product brands",
emptyText: "Please select",
valueField: "id",
lazyInit:false,
value:this.data?this.data.title:"",
hiddenName:"setid",
hiddenValue:this.data? this.data.setid:"",
displayField: "title",
typeAhead: false,
forceSelection: true,
editable:true,
listeners:{
"change ":function(combo,newvalue,oldvalue)
{
//Handle the brand's change event. After selecting the brand, reload the combobox. The editor is an instance of the roweditor defined previously
var category=editor .items.items[0].items.items[1];
var material=editor.items.items[0].items.items[2];
var c=category.getValue();
var store=material.getStore();
store.load({
params:{setid:newvalue,category:c},
callback:function(r,options,success){
if (success)
material.setValue("");
}
});
}
},
triggerAction: "all",
store: new Ext.data.JsonStore({
url: "<%=script_path%>data.asp",
root: "data",autoDestroy:true,
remoteSort: true,
listeners :{"load":function(store,records,option){
var s=Ext.data.Record.create([{name:"id",type:"int"},{name:"title" ,type:"string"}]);
store.add(new s({id:0,title:"Universal"}))
}},
baseParams: {op: "setList" },
totalProperty: "total",
autoLoad: true,
fields: ["title","id"]
})
},
{

xtype: "combo",
mode:"local",width:60,
name:"category",
fieldLabel: "category",
emptyText:"Please select",
valueField: "category",
lazyInit:false,
value:this.data?this.data.category:"",
displayField: "category",
typeAhead: false,forceSelection : true,
triggerAction: "all",
listeners:{
"change":function(combo,newvalue,oldvalue)
{
//Handle the change event of the category, after selecting After branding, reload combobox. Editor is an instance of roweditor defined previously
var sets=editor.items.items[0].items.items[0];
var material=editor.items.items[ 0].items.items[2];
var setid=sets.getValue();
var store=material.getStore();
store.load({
params:{category: newvalue,setid:setid},
callback:function(r,options,success){
if (success)
material.setValue("");
}
});
}
},

store: new Ext.data.JsonStore({
url: "<%=script_path%>data.asp",
root: "data ",autoDestroy:true,
remoteSort: true,
baseParams: {op: "materialCategoryList"},
totalProperty: "total",
autoLoad: true,
fields: ["category "]
})


},
{
xtype: "combo",
forceSelection: true,
editable:true,
mode: "local",
name:"material",
fieldLabel: "material",
emptyText:"Please select a material",
valueField: "id",
allowBlank:false,
displayField: "model",
width:250,
lazyInit:false,
typeAhead: false,
triggerAction: "all",
listeners:{
"change" :function(combo,newvalue,oldvalue)
{
//Be sure to pay attention here! ! ! If there are no two sentences below, you will find that the displayed value will not change after you select it, and it cannot be updated even if you click Confirm. Why? Because roweditor determines whether to call validateedito and afteredit by detecting the isdirty attribute of the record, it determines whether the control value corresponding to each column changes. Since the material model column corresponds to compositefield, we must let When the compositefield value changes, roweditor will call validedit and afteredit, and the compositefield value will also be called to display in the column
var comp=editor.items.items[0];
comp.setRawValue(combo .getRawValue());

}
},

store: new Ext.data.JsonStore({
url: "<%=script_path%>data. asp",
root: "data",autoDestroy:true,
remoteSort: true,
baseParams: {op: "materialList"},
totalProperty: "total",
autoLoad: false,
fields: ["model","id"]
})}
]
}


},
{
header: "quantity",
dataIndex: "qty",
width: 50,
menuDisabled: true,
editor: {
xtype: 'numberfield',
minValue:1,
allowDecimals:false
}

}
,{
header: "color",
dataIndex: "color",
width: 60,
menuDisabled : true

}
,{
header: "size",
dataIndex: "size",
width: 60,
menuDisabled: true

}

]


}


]

I would like to take this note and share it with friends in need.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I create and publish my own JavaScript libraries? How do I create and publish my own JavaScript libraries? Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser? How do I optimize JavaScript code for performance in the browser? Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How do I debug JavaScript code effectively using browser developer tools? How do I debug JavaScript code effectively using browser developer tools? Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

How do I use source maps to debug minified JavaScript code? How do I use source maps to debug minified JavaScript code? Mar 18, 2025 pm 03:17 PM

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Mar 15, 2025 am 09:19 AM

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

See all articles