最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

Extjs4GridPanel的幾種樣式使用介紹_extjs

來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 21:08:48
文檔

Extjs4GridPanel的幾種樣式使用介紹_extjs

Extjs4GridPanel的幾種樣式使用介紹_extjs:簡(jiǎn)單表格 排序,顯示某列,讀取本地?cái)?shù)據(jù) 代碼如下://本地?cái)?shù)據(jù) var datas = [ ['1', 'gao', 'man'], ['2', 'gao', 'man'], ['3', 'gao', 'man'] ]; //創(chuàng)建面板 Ext.create('Ext.grid.Panel', { title: 'easy gr
推薦度:
導(dǎo)讀Extjs4GridPanel的幾種樣式使用介紹_extjs:簡(jiǎn)單表格 排序,顯示某列,讀取本地?cái)?shù)據(jù) 代碼如下://本地?cái)?shù)據(jù) var datas = [ ['1', 'gao', 'man'], ['2', 'gao', 'man'], ['3', 'gao', 'man'] ]; //創(chuàng)建面板 Ext.create('Ext.grid.Panel', { title: 'easy gr

簡(jiǎn)單表格

排序,顯示某列,讀取本地?cái)?shù)據(jù)

代碼如下:
//本地?cái)?shù)據(jù)
var datas = [
['1', 'gao', 'man'], ['2', 'gao', 'man'], ['3', 'gao', 'man']
];
//創(chuàng)建面板
Ext.create('Ext.grid.Panel', {
title: 'easy grid',
width: 400,
height: 300,
renderTo: Ext.getBody(),
frame: true,
viewConfig: {
forceFit: true,
stripRows: true
},
store: {//配置數(shù)據(jù)代理

fields: ['id', 'name', 'gender'],
proxy: {
type: 'memory',
data: datas,
reader: 'array' //數(shù)據(jù)讀取器為 數(shù)據(jù)讀取

},
autoLoad: true
},
columns: [{ //自定義列信息
header: 'id',
width: 30,
dataIndex: 'id', //綁定fields中得字段
sortable: true
}, {
header: 'name',
width: 80,
dataIndex: 'name',
sortable: true
}, {
header: 'gender',
width: 80,
dataIndex: 'gender',
sortable: true
}

]

})

表格列:
行號(hào), bool行轉(zhuǎn)成是否,日期格式化輸出(date,top day), number數(shù)據(jù)類型格式化輸出(change,volume),Action列(操作列)

代碼;
代碼如下:
Ext.tip.QuickTipManager.init();
Ext.create('Ext.data.Store', {
storeId: 'sampleStore',
fields: [{
name: 'framework',
type: 'string'
}, {
name: 'rocks',
type: 'boolean'
}, {
name: 'volume',
type: 'number'
}, {
name: 'topday',
type: 'date'
}, {
name: 'change',
type: 'number'
}, {
name: 'date',
type: 'date'
}, {
name: 'price',
type: 'number'
}

],
data: {
'items': [{
"framework": "Ext JS 1",
"rocks": true,
"symbol": "goog",
"date": '2011/04/22',
"change": 0.8997,
"volume": 3053782,
"topday": '04/11/2010',
"price": 1000.23

}, {
"framework": "Ext JS 2",
"rocks": true,
"symbol": "goog",
"date": '2011/04/22',
"change": 0.8997,
"volume": 3053782,
"topday": '04/11/2010',
"price": 1000.23

}, {
"framework": "Ext JS 3",
"rocks": true,
"symbol": "goog",
"date": '2011/04/22',
"change": 0.8997,
"volume": 3053782,
"topday": '04/11/2010',
"price": 1000.23

}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Boolean Column Demo',
store: Ext.data.StoreManager.lookup('sampleStore'),
columns: [
Ext.create('Ext.grid.RowNumberer', { text: '行號(hào)', width: 40 }),
{
text: 'Framework',
dataIndex: 'framework',
width: 100
}, {
xtype: 'booleancolumn',
text: 'Rocks',
trueText: '是',
falseText: '否',
dataIndex: 'rocks'
}, {
text: 'Date',
dataIndex: 'date',
xtype: 'datecolumn',
format: 'Y年m月d日'
}, {
text: 'Change',
dataIndex: 'change',
xtype: 'numbercolumn',
format: '0.000'
}, {
text: 'Volume',
dataIndex: 'volume',
xtype: 'numbercolumn',
format: '0,000'
}, {
text: 'Top Day',
dataIndex: 'topday',
xtype: 'datecolumn',
format: 'l'
}, {
text: 'Current Price',
dataIndex: 'price',
renderer: Ext.util.Format.usMoney
}, {
header: '操作',
xtype: 'actioncolumn', //操作列
width: 100,
items: [{
icon: 'e.gif', // 編輯圖片地址

tooltip: ‘編輯', //鼠標(biāo)over顯示的文字 使用此功能,必須 Ext.tip.QuickTipManager.init();
handler: function (grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Edit " + rec.get('framework'));
}
}, {
icon: 'd.gif',
tooltip: 'Delete',
handler: function (grid, rowIndex,
colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Terminate " + rec.get('framework'));
}
}]

}, {

}
],
height: 200,
width: 800,
renderTo: Ext.getBody()
});

下面這個(gè)圖是 單擊 操作(編輯,刪除)按鈕觸發(fā)的回調(diào)函數(shù)的詳細(xì)信息.

下面演示 自定義 渲染函數(shù)

效果:

代碼如下:
Ext.tip.QuickTipManager.init();
function customFunction(value, metadata) {
if (value > 10) {
metadata.style = 'color:red';

}
return value;

}

Ext.create('Ext.data.Store', {
storeId: 'sampleStore',
fields: [ {
name: 'custom',
type: 'number'
}

],
data: {
'items': [{

"custom": 10

}, {

"custom": 100

}, {

"custom": 1000

}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Boolean Column Demo',
store: Ext.data.StoreManager.lookup('sampleStore'),
columns: [
Ext.create('Ext.grid.RowNumberer', { text: '行號(hào)', width: 40 }),
{
text: 'custom',
dataIndex: 'custom',
renderer: customFunction //調(diào)用自定義函數(shù) 來渲染
}
],
height: 200,
width: 800,
renderTo: Ext.getBody()
});

選擇模式:Selection

選擇模式分為三類:

1,行選擇(默認(rèn))

2.單元格選擇

3.復(fù)選框選擇(checkbox組)

演示單元格選擇代碼:

只需在上述代碼配置節(jié)當(dāng)中,加入
代碼如下:
tbar: [
{
text: '取得所選單元格',
handler: function () {

var cell = grid.getSelectionModel().getCurrentPosition(); //getSelectionModel()獲取當(dāng)前選擇模式,getCurrentPosition()獲取當(dāng)前選擇的單元格
alert(Ext.JSON.encode(cell));
}
}
],
selType:'cellmodel' //設(shè)置 選擇模式 為 單元格選擇

行選擇:

效果:

代碼如下:
tbar: [
{
text: '取得所選行',
handler: function () {

var rows = grid.getSelectionModel().getSelection(); //getSelection();獲取當(dāng)前選中的記錄數(shù)組
var msg = [];
for (var i = 0; i < rows.length; i++) {

var row = rows[i];
var myDate = new Date(row.get('date'));
msg.push('選中行的Date列:' + myDate.toLocaleString()); //轉(zhuǎn)換時(shí)間格式

}
alert(msg.join('\n'));

}
}
],
selType: 'rowmodel', //選擇模式為 行選擇
simpleSelect: true, //簡(jiǎn)單選擇功能開啟
multiSelect: true, // 啟用多行選擇
enableKeyNav: true //啟用鍵盤導(dǎo)航



復(fù)選框選擇:

效果:

代碼如下:
tbar: [
{
text: '取得所選行',
handler: function () {

var rows = grid.getSelectionModel().getSelection(); //getSelection();獲取當(dāng)前選中的記錄數(shù)組
var msg = [];
for (var i = 0; i < rows.length; i++) {

var row = rows[i];
var myDate = new Date(row.get('date'));

var s = grid.getStore(); //獲取grid的數(shù)據(jù)源
var number = s.indexOf(row) + 1; //獲取行號(hào)+1 因?yàn)樾刑?hào)從0開始

msg.push('選中第' + number + '行的Date列:' + myDate.toLocaleString());

}
alert(msg.join('\n'));

}
}
],
selType: 'checkboxmodel', //選擇模式為 行選擇
simpleSelect: true, //簡(jiǎn)單選擇功能開啟
multiSelect: true, // 啟用多行選擇
enableKeyNav: true //啟用鍵盤導(dǎo)航



表格特性: Feature

表格匯總 Ext.grid.feature.Summary

匯總值計(jì)算 根據(jù)表格的每一列進(jìn)行計(jì)算,計(jì)算方式 有指定的 summaryType決定.默認(rèn)的有

上圖5種.

此例應(yīng)用 sum和average

代碼如下:
Ext.define('TestResult', {
extend: 'Ext.data.Model',
fields: ['student', {
name: 'mark',
type: 'int'
}]
});

var grid = Ext.create('Ext.grid.Panel', {
width: 200,
height: 140,
renderTo: document.body,
features: [{
ftype: 'summary'
}],
store: {
model: 'TestResult',
data: [{
student: 'Student 1',
mark: 84
}, {
student: 'Student 2',
mark: 72
}, {
student: 'Student 3',
mark: 96
}, {
student: 'Student 4',
mark: 68
}]
},
columns: [{
dataIndex: 'student',
text: 'Name',
summaryType: 'count', //進(jìn)行匯總的列名
summaryRenderer: function (value) {
grid.getStore()
return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
}
}, {
dataIndex: 'mark',
text: 'Mark',
summaryType: 'average'
}]
})
var grid = Ext.create('Ext.grid.Panel', {
width: 200,
height: 140,
renderTo: document.body,
features: [{
ftype: 'summary'
}],
store: {
model: 'TestResult',
data: [{
student: 'Student 1',
mark: 84
}, {
student: 'Student 2',
mark: 72
}, {
student: 'Student 3',
mark: 96
}, {
student: 'Student 4',
mark: 68
}]
},
columns: [{
dataIndex: 'student',
text: 'Name',
summaryType: 'count', //進(jìn)行匯總的列名
summaryRenderer: function (value) {
// grid.getStore()
return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
}
}, {
dataIndex: 'mark',
text: 'Mark',
summaryType: 'average',

,
summaryRenderer: function (value) {
// grid.getStore()
return Ext.String.format(' 平均分為:{0}', value);


}]
})



表格分組:Ext.grid.feature.Grouping

代碼:
代碼如下:
Ext.define('TestResult', {
extend: 'Ext.data.Model',
fields: ['student', 'class', {
name: 'mark',
type: 'int'
}]
});

var grid = Ext.create('Ext.grid.Panel', {
width: 400,
height: 300,
renderTo: document.body,
features: [
Ext.create('Ext.grid.feature.Grouping',
{

groupByText: '用本字段分組',
showGroupsText: '顯示分組',
groupHeaderTpl: '班級(jí): {name} ({rows.length})', //分組顯示的模板
startCollapsed: true //設(shè)置初始分組是不是收起
})
],
store: {
model: 'TestResult',
groupField: 'class',
data: [{
student: 'Student 1',
class: '1',
mark: 84
}, {
student: 'Student 2',
class: '1',
mark: 72
}, {
student: 'Student 3',
class: '2',
mark: 96
}, {
student: 'Student 4',
class: '2',
mark: 68
}]
},
columns: [{
dataIndex: 'student',
text: 'Name',
summaryType: 'count', //進(jìn)行匯總的列名
summaryRenderer: function (value) {
grid.getStore()
return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
}
}, {
dataIndex: 'mark',
text: 'Mark',
summaryType: 'average'
},
{ dataIndex: 'class',
text: 'class'
}]
})
//在不同的列下面點(diǎn)擊 “用本字段分組”那么表格就會(huì)立即改變分組規(guī)則.

表格的分組匯總:Ext.grid.feature.GroupSummary

代碼只需要把上面的 Grouping 改成 GroupingSummary

表格插件: plugin

單元格編輯 Ext.grid.plugin.CellEditing

代碼:
代碼如下:
var datas = [['gao', Date(1922, 02, 03), 2000]];
Ext.create('Ext.grid.Panel', {

title: '演示',
frame: true,
renderTo: Ext.getBody(),
width: 400,
height: 300,

store: {
fields: ['name', 'birth', 'salary'],
data: datas,
proxy: {
type: 'memory',
data: datas,
reader: 'array'
},
autoLoad: true
},
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {

clicksToEdit: 1
})
],
selType: 'cellmodel',
columns: [Ext.create('Ext.grid.RowNumberer', { text: '行號(hào)', width: 40 }),
{
header: '姓名',
width: 80,
dataIndex: 'name',
editor: {//定義字段
xtype: 'textfield',
allowBlank: false,

}
}
,
{
header: '生日',
width: 100,
dataIndex: 'birth',
xtype: 'datecolumn',
editor: {//定義字段
xtype: 'datefield',
format: 'Y-m-d',
allowBlank: false
}
}
,
{
header: '工資',
width: 100,
dataIndex: 'salary', xtype: 'numbercolumn',
editor: {//定義字段
xtype: 'numberfield',
format: '$0,000',
allowBlank: false
}
}
]


})


表格 行編輯器Ext.grid.plugin.RowEditing

代碼只需:把 CellEditing 改成 RowEditing

想要獲取修改后的數(shù)據(jù),ajax請(qǐng)求服務(wù)器,做出響應(yīng).
代碼如下:
grid.on('edit', onEdit, this); //添加編輯事件,獲取數(shù)據(jù)
function onEdit(e) {
alert(e.record.get('name')); //get()參數(shù)是字段名字.
}


gridpanel中的checkbox列 根據(jù)數(shù)據(jù)庫值 來初始化是否被選
代碼如下:
listeners: {
load: function(store) {
var index = 0;
store.each(function(record) {
if(record.data.column_name == '1') { //column_name 替換成你的列名, '1' 替換成你的值
grid.selModel.selectRow(index,true);
}
index++;
})
}
}

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

文檔

Extjs4GridPanel的幾種樣式使用介紹_extjs

Extjs4GridPanel的幾種樣式使用介紹_extjs:簡(jiǎn)單表格 排序,顯示某列,讀取本地?cái)?shù)據(jù) 代碼如下://本地?cái)?shù)據(jù) var datas = [ ['1', 'gao', 'man'], ['2', 'gao', 'man'], ['3', 'gao', 'man'] ]; //創(chuàng)建面板 Ext.create('Ext.grid.Panel', { title: 'easy gr
推薦度:
標(biāo)簽: 介紹 grid panel
  • 熱門焦點(diǎn)
專題
Top
fffffffffffff

抖音扫码关注

手机端二维码

每天分享百科知识!