1.修改默認(rèn)的json格式為key:value
修改前
修改后
源碼修改說明
找到 if (p.dataType=='json')將其后的大括號(hào){}內(nèi)容改為:
$.each
(
data.rows,
function(i,row)
{
var tr = document.createElement('tr');
if (i % 2 && p.striped) tr.className = 'erow';
if (row.id) tr.id = 'row' + row.id;
//by anson QQ:75526201 chents@gpcsoft.com 轉(zhuǎn)載請(qǐng)保留
var tdVal = [];
//給每行添加id
if (p.rowId){
$.each( data.rows[i], function(x,y){
if(p.rowId==x){tr.setAttribute('id',y);
}
})
}
if (p.colModel){
for (j=0;j<p.colModel.length;j++){
var cm = p.colModel[j];
//取列名
var seleceName = cm.name;
//json Bug修復(fù)://打包文件中未加入,請(qǐng)自行加入
if(typeof(data.rows[i][seleceName])=='undefined'){data.rows[i][seleceName]=''}
//過濾key
$.each( data.rows[i], function(x,y){
if(seleceName==x){tdVal.push(y)}
})
}
}
//add cell
$('thead tr:first th',g.hDiv).each
(
function ()
{
var td = document.createElement('td');
var idx = $(this).attr('axis').substr(3);
td.align = this.align;
td.innerHTML = tdVal[idx];
//td.innerHTML = row.cell[idx];
$(tr).append(td);
td = null;
}
);
if ($('thead',this.gDiv).length<1) //handle if grid has no headers
{
for (idx=0;idx<cell.length;idx++)
{
var td = document.createElement('td');
//td.innerHTML = row.cell[idx];
td.innerHTML = tdVal[idx];
$(tr).append(td);
td = null;
}
}
$(tbody).append(tr);
tr = null;
}
);
2.加入checkbox
只要設(shè)置checkbox:true即可在前面顯示多選框
源碼修改說明
a.找到 $('div:eq('+n+')',g.cDrag).css({'left':cdpos+'px'}).show();
替換為:
if (p.checkbox) {
$('div:eq('+n+')',g.cDrag).css({'left':cdpos+22+'px'}).show();
}
else{
$('div:eq('+n+')',g.cDrag).css({'left':cdpos+'px'}).show();
}
b.找到//add cell
前面插入:
//添加多選框
if (p.checkbox) {
var cth = $('<th/>');
var cthch = $('<input type="checkbox" value="' + $(tr).attr('id') +'"/>');
var objTr = $(tr);
cthch.addClass("noborder").click(function(){
if(this.checked){
objTr.addClass('trSelected');
}
else{
objTr.removeClass('trSelected');
}
})
cth.addClass("cth").attr({ width: "22"}).append(cthch);
$(tr).prepend(cth);
}
c.找到$(this).toggleClass('trSelected');
后面插入:
if(p.checkbox){
if($(this).hasClass('trSelected')){
$(this).find('input')[0].checked=true;
}
else{
$(this).find('input')[0].checked=false
}
}
d.找到if ($('th',g.hDiv).length)
在其后的{}大括號(hào)中加入
//添加多選框
if (p.checkbox) {
$('tr',g.hDiv).each(
function(){
var cth = $('<td/>');
var cthch = $('<input type="checkbox"/>');
cthch.click(function(){
if(this.checked){
$('tbody tr',g.bDiv).each(function(){
$(this).addClass('trSelected').find('input')[0].checked=true;
})
}
else{
$('tbody tr',g.bDiv).each(function(){
$(this).removeClass('trSelected').find('input')[0].checked=false;
})
}
})
cth.addClass("cth").attr({ width: "22" }).append(cthch);
$(this).prepend(cth);
})
};
e.找到p = $.extend({
添加默認(rèn)設(shè)置
rowId:'id',//綁定行的id
修改后結(jié)果
未加入多條件搜索,右鍵,打印,導(dǎo)出Excel等功能,如有需要聯(lián)系作者Anson,QQ:75526201
修改后文件下載:點(diǎn)擊下載附件
http://hi.baidu.com/wzjstrong/blog/item/fc64e036da94221d90ef393b.html
http://blog.csdn.net/liuzhoulong/article/details/6076071
jQuery插件flexigrid是像ext的DataGrid一樣的活動(dòng)表格插件,使用它首先要引入query.js,還要引入flexigrid.js和flexigrid.css
最后上圖(用highcharts和flexigrid實(shí)現(xiàn)):
