ExtGrid의 예

2669 단어 ext
Ext.onReady(function(){
	// 
	var logData = [
		['2012-07-11/09:38:27',' ','TCP','10.230.235.158','10.1.17.49','3855','8001',' '],
		['2012-08-11/09:33:27',' ','UDP','10.230.235.158','10.1.17.49','3855','8001',' '],
		['2012-09-11/09:38:27',' ','tcp','10.230.235.158','10.1.17.49','3855','8001',' ']		
	]
	
	var store = new Ext.data.ArrayStore({
		fields:[
			{name:'time'},
			{name:'name'},
			{name:'protocol'},
			{name:'srcIP'},
			{name:'dstIP'},
			{name:'srcPort'},
			{name:'dstPort'},
			{name:'level'}
		],
		sortInfo: {field: 'time', direction: 'DESC'}
	});
	
	store.loadData(logData);
	
	// 
	var grid = new Ext.grid.GridPanel({
		viewConfig:{
			forceFit:true
		},
		store:store,
		autoHeight:true,
		renderTo:'showLog',
		stripeRows:true,
		columns:[
			{header:' ', dataIndex:'time'},
			{header:' ', dataIndex:'name'},
			{header:' ', dataIndex:'protocol'},
			{header:' IP', dataIndex:'srcIP'},
			{header:' IP', dataIndex:'dstIP'},
			{header:' ', dataIndex:'srcPort'},
			{header:' ', dataIndex:'dstPort'},
			{header:' ', dataIndex:'level'}
		]
	});
	var LogRecord = Ext.data.Record.create([ 
    		{name:'time'},
			{name:'name'},
			{name:'protocol'},
			{name:'srcIP'},
			{name:'dstIP'},
			{name:'srcPort'},
			{name:'dstPort'},
			{name:'level'} 
	]);
	
	var AddNewRecord = function(){
		var time = new Date().format('Y-m-d/H:i:s');
		var interval = parseInt(Math.random()*3000+1); // 
		var newRecord = new LogRecord({
			time:time,
			name:' ',
			protocol:'TCP',
			srcIP:'10.230.235.158',
			dstIP:'10.1.17.49',
			srcPort:'3855',
			dstPort:'8001',
			level:' '
		});
		store.addSorted(newRecord);
		setTimeout(AddNewRecord,interval);
	}
	Ext.get('add').on('click',AddNewRecord);
	
})

좋은 웹페이지 즐겨찾기