将其后的大括号{}内容改为:
$.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 转载请保留var tdVal = [];//给每行添加idif (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修复://打包文件中未加入,请自行加入 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;});
替换为:
前面插入:
//添加多选框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);
}
后面插入:
在其后的{}大括号中加入
//添加多选框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);})};
添加默认设置
修改后文件下载:点击下载附件
$("#flex1").flexigrid({ url: 'post2.php', dataType: 'json', colModel : [ {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} ], buttons : [ {name: 'Add', bclass: 'add', onpress : test}, {name: 'Delete', bclass: 'delete', onpress : test}, {separator: true} ], searchitems : [ {display: 'ISO', name : 'iso'}, {display: 'Name', name : 'name', isdefault: true} ], sortname: "iso", sortorder: "asc", usepager: true, title: 'Countries', useRp: true, rp: 15, showTableToggleBtn: true, width: 700, height: 200 });