A query box can be found below the table header, such as the attachment diagram.CodeAs follows:
Ext. Override (ext. Grid. gridview ,{
/**
* Query a single cell element by subscript
**/
Getsearchcell: function (INDEX ){
Return this. mainsh. Dom. getelementsbytagname ('td ') [Index];
},
/**
* Manually drag the width of the header Column
**/
Updatecolumnwidth: function (column, width ){
VaR columnwidth = This. getcolumnwidth (column ),
Totalwidth = This. gettotalwidth (),
Headercell = This. getheadercell (column ),
Searchcell = This. getsearchcell (column), // get the query cell Element
Nodes = This. getrows (),
Nodecount = nodes. length,
Row, I, firstchild;
This. updateheaderwidth ();
This. updatesearchwidth (); // update the width of all query Columns
Headercell. style. width = columnwidth;
Searchcell. style. width = columnwidth; // update the width of the current cell.
For (I = 0; I <nodecount; I ++ ){
Row = nodes [I];
Firstchild = row. firstchild;
Row. style. width = totalwidth;
If (firstchild ){
Firstchild. style. width = totalwidth;
Firstchild. Rows [0]. childnodes [column]. style. width = columnwidth;
}
}
This. oncolumnwidthupdated (column, columnwidth, totalwidth );
},
Renderui: function (){
VaR templates = This. templates;
Return templates. master. Apply ({
Body: templates. Body. Apply ({rows: '& #160 ;'}),
Header: This. renderheaders (),
Ostyle: 'width: '+ this. getoffsetwidth () + ';',
Bstyle: 'width: '+ this. gettotalwidth () + ';',
Search: This. rendersearch () // Rendering
});
},
/**
* Update query Columns
**/
Updatesearch: function (){
This. innersh. firstchild. innerhtml = This. rendersearch ();
This. updatesearchwidth (false );
},
/**
* Update the query column width.
*/
Updatesearchwidth: function (updatemain ){
VaR innershchild = This. innersh. firstchild,
Totalwidth = This. gettotalwidth ();
Innershchild. style. width = This. getoffsetwidth ();
Innershchild. firstchild. style. width = totalwidth;
If (updatemain! = False ){
This. mainbody. Dom. style. width = totalwidth;
}
},
Initelements: function (){
VaR element = ext. element,
El = ext. Get (this. Grid. getgridel (). Dom. firstchild ),
Mainwrap = new element (El. Child ('div. x-grid3-viewport ')),
Mainhd = new element (mainwrap. Child ('div. x-grid3-header ')),
Mainsh = new element (mainwrap. Child ('div. x-grid3-search '), // Add query rows based on the original
Scroroller = new element (mainwrap. Child ('div. x-grid3-scroller '));
If (this. Grid. hideheaders ){
Mainhd. setdisplayed (false );
}
If (this. forcefit ){
Scroller. setstyle ('overflow-x', 'hidd ');
}
/**
* <I> Read-Only </I>. The gridview's body element which encapsulates all rows in the grid.
* This {@ link Ext. element} is only available after the gridpanel has been rendered.
* @ Type Ext. Element
* @ Property mainbody
*/
Ext. Apply (this ,{
El: El,
Mainwrap: mainwrap,
Scroroller: scroroller,
Mainhd: mainhd, in arrears
Mainsh: mainsh,
Innerhd: mainhd. Child ('div. x-grid3-header-inner '). Dom,
Innersh: mainsh. Child ('div. x-grid3-search-inner '). Dom, // Add the query column on the basis of the original
Mainbody: new element (element. Fly (scroller). Child ('div. x-grid3-body ')),
Focusel: new element (element. Fly (scroller). Child ('A ')),
Resizemarker: new element (El. Child ('div. x-grid3-resize-marker ')),
Resizeproxy: new element (El. Child ('div. x-grid3-resize-proxy '))
});
This. focusel. swallowevent ('click', true );
},
Mastertpl: New Ext. template (
'<Div class = "x-grid3" hidefocus = "true"> ',
'<Div class = "x-grid3-viewport"> ',
'<Div class = "x-grid3-header"> ',
'<Div class = "x-grid3-header-inner"> ',
'<Div class = "x-grid3-header-offset" style = "{ostyle}"> {header} </div> ',
'</Div> ',
'<Div class = "X-clear"> </div> ',
'</Div> ',
// Template required by the query box
'<Div class = "x-grid3-search"> ',
'<Div class = "x-grid3-search-inner"> ',
'<Div class = "x-grid3-search-offset" style = "{ostyle}"> {search} </div> ',
'</Div> ',
'<Div class = "X-clear"> </div>', Women's brand list
'</Div> ',
// ======================================
'<Div class = "x-grid3-scroller"> ',
'<Div class = "x-grid3-body" style = "{bstyle}"> {body} </div> ',
'<A href = "#" class = "x-grid3-focus" tabindex = "-1"> </a> ',
'</Div> ',
'</Div> ',
'<Div class = "x-grid3-resize-marker" >&# 160; </div> ',
'<Div class = "x-grid3-resize-proxy" >&# 160; </div> ',
'</Div>'
),
/**
* Rendering query table
**/
Rendersearch: function (){
VaR colmodel = This. cm,
Templates = This. templates,
Properties = {},
Colcount = colmodel. getcolumncount (),
Searchcells = [],
I;
Templates. scell = new Ext. template (
'<TD style = "{style}"> <Div id = "search-{ID}"> </div> </TD>' // column template, ID can be set in columnmodel. If not, it starts from 0. For example, search-0 and search-2. Then we use search-{ID} to render the query control we need.
);
Templates. seatchtpl = new Ext. template (
'<Table border = "0" cellspacing = "0" cellpadding = "0" style = "{tstyle}"> <tr> {cells} </tr> </table> '// template of the entire query box
);
For (I = 0; I <colcount; I ++ ){
Properties = {
ID: colmodel. getcolumnid (I ),
Style: This. getcolumnstyle (I, true)
};
Searchcells [I] = templates. scell. Apply (properties );
}
Return templates. seatchtpl. Apply ({
Cells: searchcells. Join (""),
Tstyle: String. Format ("width: {0};", this. gettotalwidth ())
});
}
});
Usage:
Note that after the table data is loaded, you must pay attention to the following sequence, or you cannot render it.
// Example
VaR combo = new Ext. Form. ComboBox ({
Store: store,
Displayfield: 'state ',
Mode: 'local ',
Triggeraction: 'all ',
Width: 100,
Renderto: 'search-2' // This is the ID of the rendered Div, which is defined in templates. scell.
});