EXTJS GridPanel排序
Ext.onReady(function(){
<%
List<Getmateriel> getmateriel= (List<Getmateriel>)request.getAttribute("getmateriel");
String s="";
for (int i=0;i<getmateriel.size();i++){
s=s+"['"+(i+1)+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getCode().toString()+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getNname().toString()+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getNdate().toString()+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getOname().toString()+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getOdate().toString()+"',";
s=s+"'"+((Getmateriel)getmateriel.get(i)).getId().toString()+"',";
String dis=((Getmateriel)getmateriel.get(i)).getDis().toString();
if((i+1)==getmateriel.size())
{
if(dis.equals("0"))
s=s+"'未签字']";
else
s=s+"'已签字']";
}
else
{
if(dis.equals("0"))
s=s+"'未签字'],";
else
s=s+"'已签字'],";
}
}
%>
var myData = [
<%= s%>
];
<% s=null;
System.gc();
%>
// example of custom renderer function
function change(val){
if(val > 0){
return '<span style="color:green;">' + val + '</span>';
}else if(val < 0){
return '<span style="color:red;">' + val + '</span>';
}
return val;
}
// example of custom renderer function
function pctChange(val){
if(val > 0){
return '<span style="color:green;">' + val + '%</span>';
}else if(val < 0){
return '<span style="color:red;">' + val + '%</span>';
}
return val;
}
// create the data store
var store = new Ext.data.Store({
proxy: new Ext.ux.data.PagingMemoryProxy(myData),
remoteSort:true,
sortInfo: {field:'序号', direction:'DESC'},
reader: new Ext.data.ArrayReader({
fields: [
{name: '序号'},
{name: '领料单号'},
{name: '领料人'},
{name: '领料日期'},
{name: '仓库签字'},
{name: '日期'},
{name: 'id'},
{name: '是否生效'}
]
})
});
// create the Grid
var grid = new Ext.grid.GridPanel({
id: "detailPanel",
store: store,
columns: [
{id:'序号',header: "序号", width: 20, sortable: true, dataIndex: '序号'},
{header: "领料单号", width: 175 , sortable: true, dataIndex: '领料单号'},
{header: "领料人", width: 75 , sortable: true, dataIndex: '领料人'},
{header: "领料日期", width: 125, sortable: true, dataIndex: '领料日期'},
{header: "仓库签字", width: 75, sortable: true, dataIndex: '仓库签字'},
{header: "日期", width: 125, sortable: true, dataIndex: '日期'},
{header: "id",hidden:true, width: 75, sortable: true, dataIndex: 'id'},
{header: "是否生效", width: 85, sortable: true, dataIndex: '是否生效'}
],
stripeRows: true,
autoExpandColumn: '序号',
height:Ext.get("grid-example").getHeight(),
width:Ext.get("grid-example").getWidth(),
frame:true,
title:'材料出库',
viewConfig:
{
columnsText:'列',
sortAscText:'升序',
sortDescText:'降序',
getRowClass : function(record,rowIndex,rowParams,store){
if(record.data.是否生效=="未签字"){
return 'x-grid-record-red';
}else{
return '';
}
}
},
plugins: new Ext.ux.PanelResizer({
minHeight: 100
}),
bbar: new Ext.PagingToolbar({
pageSize: 24,
store: store,
displayInfo: true,
plugins: new Ext.ux.ProgressBarPager()
})
});
grid.render('grid-example');
function rowdblclickFn(grid, rowIndex, e){//双击事件
var row = grid.store.getById(grid.store.data.items[rowIndex].id);
var url; //转向网页的地址;
var name; //网页名称,可为空;
var iWidth=900; //弹出窗口的宽度;
var iHeight=668; //弹出窗口的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
// window.open("/erp/buy/queryonestock?id='"+row.get("id")+"'","re",'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',易做图=no,menubar=no,scrollbars=yes,resizeable=no,location=no,status=no');
window.location.href="/erp/produce/queryoneproduce?id='"+row.get("id")+"'";
}
grid.addListener('rowdblclick', rowdblclickFn);
store.load({params:{start:0, limit:25}});
}
);
代码如上
载入时候 红色部分默认应该是倒序 但是输出却是升序 如果改成ASC 却不是升序 也不是倒序 无序
后面修改排序效果也是和上面一样
--------------------编程问答-------------------- 怎么没显红色
就是这行 sortInfo: {field:'序号', direction:'DESC'}, --------------------编程问答--------------------
补充:Java , Java EE