var detailview = $.extend({}, $.fn.datagrid.defaults.view, { render: function(target, container, frozen){ var state = $.data(target, 'datagrid'); var opts = state.options; if (frozen){ if (!(opts.rownumbers || (opts.frozenColumns && opts.frozenColumns.length))){ return; } } var rows = state.data.rows; var fields = $(target).datagrid('getColumnFields', frozen); var table = []; table.push(''); for(var i=0; i'); table.push(this.renderRow.call(this, target, fields, frozen, i, rows[i])); table.push(''); table.push(''); if (frozen){ table.push(''); table.push(''); } table.push('
'); } else { table.push(''); } table.push('
'); if (frozen){ table.push(' '); } else { table.push(opts.detailFormatter.call(target, i, rows[i])); } table.push('
'); table.push('
'); $(container).html(table.join('')); }, renderRow: function(target, fields, frozen, rowIndex, rowData){ var opts = $.data(target, 'datagrid').options; var cc = []; if (frozen && opts.rownumbers){ var rownumber = rowIndex + 1; if (opts.pagination){ rownumber += (opts.pageNumber-1)*opts.pageSize; } cc.push('
'+rownumber+'
'); } for(var i=0; i'); if (col.checkbox){ style = ''; } else if (col.expander){ style = "text-align:center;height:16px;"; } else { style = styleValue; if (col.align){style += ';text-align:' + col.align + ';'} if (!opts.nowrap){ style += ';white-space:normal;height:auto;'; } else if (opts.autoRowHeight){ style += ';height:auto;'; } } cc.push('
'); if (col.checkbox){ cc.push(''); } else if (col.expander) { //cc.push('
'); cc.push(''); //cc.push('
'); } else if (col.formatter){ cc.push(col.formatter(value, rowData, rowIndex)); } else { cc.push(value); } cc.push('
'); cc.push(''); } } return cc.join(''); }, insertRow: function(target, index, row){ var opts = $.data(target, 'datagrid').options; var dc = $.data(target, 'datagrid').dc; var panel = $(target).datagrid('getPanel'); var view1 = dc.view1; var view2 = dc.view2; var isAppend = false; var rowLength = $(target).datagrid('getRows').length; if (rowLength == 0){ $(target).datagrid('loadData',{total:1,rows:[row]}); return; } if (index == undefined || index == null || index >= rowLength) { index = rowLength; isAppend = true; this.canUpdateDetail = false; } $.fn.datagrid.defaults.view.insertRow.call(this, target, index, row); _insert(true); _insert(false); this.canUpdateDetail = true; function _insert(frozen){ var v = frozen ? view1 : view2; var tr = v.find('tr[datagrid-row-index='+index+']'); if (isAppend){ var newDetail = tr.next().clone(); tr.insertAfter(tr.next()); } else { var newDetail = tr.next().next().clone(); } newDetail.insertAfter(tr); newDetail.hide(); if (!frozen){ newDetail.find('div.datagrid-row-detail').html(opts.detailFormatter.call(target, index, row)); } } }, deleteRow: function(target, index){ var opts = $.data(target, 'datagrid').options; var dc = $.data(target, 'datagrid').dc; var tr = opts.finder.getTr(target, index); tr.next().remove(); $.fn.datagrid.defaults.view.deleteRow.call(this, target, index); dc.body2.triggerHandler('scroll'); }, updateRow: function(target, rowIndex, row){ var dc = $.data(target, 'datagrid').dc; var opts = $.data(target, 'datagrid').options; var cls = $(target).datagrid('getExpander', rowIndex).attr('class'); $.fn.datagrid.defaults.view.updateRow.call(this, target, rowIndex, row); $(target).datagrid('getExpander', rowIndex).attr('class',cls); // update the detail content if (this.canUpdateDetail){ var row = $(target).datagrid('getRows')[rowIndex]; var detail = $(target).datagrid('getRowDetail', rowIndex); detail.html(opts.detailFormatter.call(target, rowIndex, row)); } }, bindEvents: function(target){ var state = $.data(target, 'datagrid'); var dc = state.dc; var opts = state.options; var body = dc.body1.add(dc.body2); var clickHandler = ($.data(body[0],'events')||$._data(body[0],'events')).click[0].handler; body.unbind('click').bind('click', function(e){ var tt = $(e.target); var tr = tt.closest('tr.datagrid-row'); if (!tr.length){return} if (tt.hasClass('datagrid-row-expander')){ var rowIndex = parseInt(tr.attr('datagrid-row-index')); if (tt.hasClass('datagrid-row-expand')){ $(target).datagrid('expandRow', rowIndex); } else { $(target).datagrid('collapseRow', rowIndex); } $(target).datagrid('fixRowHeight'); } else { clickHandler(e); } e.stopPropagation(); }); }, onBeforeRender: function(target){ var state = $.data(target, 'datagrid'); var opts = state.options; var dc = state.dc; var t = $(target); var hasExpander = false; var fields = t.datagrid('getColumnFields',true).concat(t.datagrid('getColumnFields')); for(var i=0; i
'); if ($('tr',t).length == 0){ td.wrap('').parent().appendTo($('tbody',t)); } else if (opts.rownumbers){ td.insertAfter(t.find('td:has(div.datagrid-header-rownumber)')); } else { td.prependTo(t.find('tr:first')); } } var that = this; setTimeout(function(){ that.bindEvents(target); },0); }, onAfterRender: function(target){ var that = this; var state = $.data(target, 'datagrid'); var dc = state.dc; var opts = state.options; var panel = $(target).datagrid('getPanel'); $.fn.datagrid.defaults.view.onAfterRender.call(this, target); if (!state.onResizeColumn){ state.onResizeColumn = opts.onResizeColumn; } if (!state.onResize){ state.onResize = opts.onResize; } function setBodyTableWidth(){ var columnWidths = dc.view2.children('div.datagrid-header').find('table').width(); dc.body2.children('table').width(columnWidths); } opts.onResizeColumn = function(field, width){ setBodyTableWidth(); var rowCount = $(target).datagrid('getRows').length; for(var i=0; i