// _f.Grid _f.cur_grid_cell = null; _f.Grid = function(parent) { } _f.Grid.prototype.init = function(parent, row_height) { this.col_idx_by_name = {} this.alt_row_bg = '#F2F2FF'; this.row_height = row_height; // make the grid if(!row_height)this.row_height = '26px'; this.make_ui(parent); // Sr No this.insert_column('', '', 'Int', 'Sr', '50px', '', [1,0,0]); if(this.oninit)this.oninit(); keypress_observers.push(this); } _f.Grid.prototype.make_ui = function(parent) { var ht = make_table($a(parent, 'div'), 1, 2, '100%', ['60%','40%']); this.main_title = $td(ht,0,0); this.main_title.className = 'columnHeading'; $td(ht,0,1).style.textAlign = 'right'; this.tbar_div = $a($td(ht,0,1), 'div', 'grid_tbarlinks'); if(isIE) $y(this.tbar_div, {width:'200px'}); this.tbar_tab = make_table(this.tbar_div,1,4,'100%',['25%','25%','25%','25%']); this.wrapper = $a(parent, 'div', 'grid_wrapper'); $h(this.wrapper, cint(screen.width * 0.5) + 'px'); this.head_wrapper = $a(this.wrapper, 'div', 'grid_head_wrapper'); this.head_tab = $a(this.head_wrapper, 'table', 'grid_head_table'); this.head_row = this.head_tab.insertRow(0); this.tab_wrapper = $a(this.wrapper, 'div', 'grid_tab_wrapper'); this.tab = $a(this.tab_wrapper, 'table', 'grid_table'); var me = this; this.wrapper.onscroll = function() { me.head_wrapper.style.top = me.wrapper.scrollTop+'px'; } } _f.Grid.prototype.show = function() { if(this.can_add_rows) { $ds(this.tbar_div); } else { $dh(this.tbar_div); } $ds(this.wrapper); } _f.Grid.prototype.hide = function() { $dh(this.wrapper); $dh(this.tbar_div); } _f.Grid.prototype.insert_column = function(doctype, fieldname, fieldtype, label, width, options, perm, reqd) { var idx = this.head_row.cells.length; if(!width)width = '140px'; if((width+'').slice(-2)!='px') { width= width + 'px'; } var col = this.head_row.insertCell(idx); col.doctype = doctype; // for report (fields may be from diff doctypes) col.fieldname = fieldname; col.fieldtype = fieldtype; col.innerHTML = '
'+label+'
'; col.label = label; if(reqd) col.childNodes[0].style.color = "#D22"; col.style.width = width; col.options = options; col.perm = perm; this.col_idx_by_name[fieldname] = idx; } _f.Grid.prototype.reset_table_width = function() { var w = 0; for(var i=0, len=this.head_row.cells.length; i=37 && keycode<=40 && e.shiftKey) { if(text_dialog && text_dialog.display) { return; } } else return; if(!_f.cur_grid_cell) return; if(_f.cur_grid_cell.grid != this) return; var ri = _f.cur_grid_cell.row.rowIndex; var ci = _f.cur_grid_cell.cellIndex; switch(keycode) { case 38: // up if (ri > 0) { this.cell_select('', ri - 1, ci); } break; case 40: // down if (ri < (this.tab.rows.length - 1)) { this.cell_select('', ri + 1, ci); } break; case 39: // right if (ci < (this.head_row.cells.length - 1)) { this.cell_select('', ri, ci + 1); } break; case 37: // left if (ci > 1) { this.cell_select('', ri, ci - 1); } break; } } _f.Grid.prototype.make_template = function(hc) { hc.template = make_field(get_field(hc.doctype, hc.fieldname), hc.doctype, '', this.field.frm, true); hc.template.grid = this; } _f.Grid.prototype.append_rows = function(n) { for(var i=0;i this.tab.rows.length) this.append_rows(data.length - this.tab.rows.length); // truncate if reqd if(data.length < this.tab.rows.length) this.truncate_rows(this.tab.rows.length - data.length); // set data for(var ridx=0;ridx cint(0.3 * screen.width))ht=cint(0.3 * screen.width); ht += 4; $y(this.wrapper,{height:ht+'px'}); } _f.Grid.prototype.refresh_row = function(ridx, docname) { var row = this.tab.rows[ridx]; row.docname = docname; row.is_newrow = false; for(var cidx=0; cidx