Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
- /**
- * Override this function to apply custom css classes to rows during rendering
- * @param {Record} record The record
- * @param {Number} index
- * @method getRowClass
- */
+ unselectable : 'unselectable="on"',
+ unselectableCls : 'x-unselectable',
+
+
rowClass : "x-grid-row",
cellClass : "x-grid-col",
if(!tpls.hcell){
tpls.hcell = new Roo.Template(
- '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
- '<div class="x-grid-hd-text" unselectable="on">{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
+ '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div " title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
+ '<div class="x-grid-hd-text ' + this.unselectableCls + '" ' + this.unselectable +'>{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
"</div></td>"
);
tpls.hcell.disableFormats = true;
tpls.hcell.compile();
if(!tpls.hsplit){
- tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style}" unselectable="on"> </div>');
+ tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style} ' +
+ this.unselectableCls + '" ' + this.unselectable +'> </div>');
tpls.hsplit.disableFormats = true;
}
tpls.hsplit.compile();
if(!tpls.cell){
tpls.cell = new Roo.Template(
'<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
- '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text" unselectable="on" {attr}>{value}</div></div>',
+ '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text ' +
+ this.unselectableCls + '" ' + this.unselectable +'" {attr}>{value}</div></div>',
"</td>"
);
tpls.cell.disableFormats = true;
this.rowEl.elements = els;
return this.rowEl;
},
-
+ /**
+ * Gets the 'td' of the cell
+ *
+ * @param {Integer} rowIndex row to select
+ * @param {Integer} colIndex column to select
+ *
+ * @return {Object}
+ */
getCell : function(rowIndex, colIndex){
var locked = this.cm.getLockedCount();
var source;
p.cellId = "x-grid-hd-0-" + i;
p.splitId = "x-grid-csplit-0-" + i;
p.id = cm.getColumnId(i);
- p.title = cm.getColumnTooltip(i) || "";
+ p.title = cm.getColumnTooltip(i) || cm.getColumnHeader(i) || "";
p.value = cm.getColumnHeader(i) || "";
p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
if(!cm.isLocked(i)){
if(s){ // splitters not created yet
var pos = 0, locked = true;
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
- if(cm.isHidden(i)) continue;
+ if(cm.isHidden(i)) {
+ continue;
+ }
var w = cm.getColumnWidth(i); // make sure it's a number
if(!cm.isLocked(i) && locked){
pos = 0;
name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
renderer : cm.getRenderer(i),
id : cm.getColumnId(i),
- locked : cm.isLocked(i)
+ locked : cm.isLocked(i),
+ has_editor : cm.isCellEditable(i)
};
}
p.id = c.id;
p.css = p.attr = "";
p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
- if(p.value == undefined || p.value === "") p.value = " ";
- if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
- p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
+ if(p.value == undefined || p.value === "") {
+ p.value = " ";
+ }
+ if(c.has_editor){
+ p.css += ' x-grid-editable-cell';
+ }
+ if(c.dirty && typeof r.modified[c.name] !== 'undefined'){
+ p.css += ' x-grid-dirty-cell';
}
var markup = ct.apply(p);
if(!c.locked){
record: r,
rowIndex : rowIndex,
rowClass : ''
- }
+ };
this.grid.fireEvent('rowclass', this, rowcfg);
alt.push(rowcfg.rowClass);
}
// buffers
var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
var hasListener = this.grid.hasListener('rowclass');
+
var rowcfg = {};
for(var j = 0, len = rs.length; j < len; j++){
r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
p.id = c.id;
p.css = p.attr = "";
p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
- if(p.value == undefined || p.value === "") p.value = " ";
+ if(p.value == undefined || p.value === "") {
+ p.value = " ";
+ }
+ //Roo.log(c);
+ if(c.has_editor){
+ p.css += ' x-grid-editable-cell';
+ }
if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
- p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
+ p.css += ' x-grid-dirty-cell'
}
+
var markup = ct.apply(p);
if(!c.locked){
cb[cb.length] = markup;
record: r,
rowIndex : rowIndex,
rowClass : ''
- }
+ };
this.grid.fireEvent('rowclass', this, rowcfg);
alt.push(rowcfg.rowClass);
}
+
rp.alt = alt.join(" ");
rp.cells = lcb.join("");
lbuf[lbuf.length] = rt.apply(rp);
if(this.enableMoveAnim && Roo.enableFx){
this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
}
+ // if multisort - fix sortOrder, and reload..
+ if (this.grid.dataSource.multiSort) {
+ // the we can call sort again..
+ var dm = this.grid.dataSource;
+ var cm = this.grid.colModel;
+ var so = [];
+ for(var i = 0; i < cm.config.length; i++ ) {
+
+ if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined')) {
+ continue; // dont' bother, it's not in sort list or being set.
+ }
+
+ so.push(cm.config[i].dataIndex);
+ };
+ dm.sortOrder = so;
+ dm.load(dm.lastOptions);
+
+
+ }
+
},
updateCell : function(dm, rowIndex, dataIndex){
};
var renderer = cm.getRenderer(colIndex);
var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
- if(typeof val == "undefined" || val === "") val = " ";
+ if(typeof val == "undefined" || val === "") {
+ val = " ";
+ }
cellText.innerHTML = val;
cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
this.syncRowHeights(rowIndex, rowIndex);
},
updateHeaderSortState : function(){
- var state = this.ds.getSortState();
- if(!state){
- return;
- }
- this.sortState = state;
- var sortColumn = this.cm.findColumnIndex(state.field);
- if(sortColumn != -1){
- var sortDir = state.direction;
- var sc = this.sortClasses;
- var hds = this.el.select(this.headerSelector).removeClass(sc);
- hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
+
+ // sort state can be single { field: xxx, direction : yyy}
+ // or { xxx=>ASC , yyy : DESC ..... }
+
+ var mstate = {};
+ if (!this.ds.multiSort) {
+ var state = this.ds.getSortState();
+ if(!state){
+ return;
+ }
+ mstate[state.field] = state.direction;
+ // FIXME... - this is not used here.. but might be elsewhere..
+ this.sortState = state;
+
+ } else {
+ mstate = this.ds.sortToggle;
+ }
+ //remove existing sort classes..
+
+ var sc = this.sortClasses;
+ var hds = this.el.select(this.headerSelector).removeClass(sc);
+
+ for(var f in mstate) {
+
+ var sortColumn = this.cm.findColumnIndex(f);
+
+ if(sortColumn != -1){
+ var sortDir = mstate[f];
+ hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
+ }
}
+
+
+
},
- handleHeaderClick : function(g, index){
+
+ handleHeaderClick : function(g, index,e){
+
+ Roo.log("header click");
+
+ if (Roo.isTouch) {
+ // touch events on header are handled by context
+ this.handleHdCtx(g,index,e);
+ return;
+ }
+
+
if(this.headersDisabled){
return;
}
return;
}
g.stopEditing();
+
+ if (dm.multiSort) {
+ // update the sortOrder
+ var so = [];
+ for(var i = 0; i < cm.config.length; i++ ) {
+
+ if ((typeof(dm.sortToggle[cm.config[i].dataIndex]) == 'undefined') && (index != i)) {
+ continue; // dont' bother, it's not in sort list or being set.
+ }
+
+ so.push(cm.config[i].dataIndex);
+ };
+ dm.sortOrder = so;
+ }
+
+
dm.sort(cm.getDataIndex(index));
},
cm.setLocked(index, false);
}
break;
+ case 'wider': // used to expand cols on touch..
+ case 'narrow':
+ var cw = cm.getColumnWidth(index);
+ cw += (item.id == 'wider' ? 1 : -1) * 50;
+ cw = Math.max(0, cw);
+ cw = Math.min(cw,4000);
+ cm.setColumnWidth(index, cw);
+ break;
+
default:
index = cm.getIndexById(item.id.substr(4));
if(index != -1){
{id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
);
}
+ if (Roo.isTouch) {
+ this.hmenu.add('-',
+ {id:"wider", text: this.columnsWiderText},
+ {id:"narrow", text: this.columnsNarrowText }
+ );
+
+
+ }
+
if(this.grid.enableColumnHide !== false){
this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
this.dd = new Roo.grid.GridDragZone(this.grid, {
ddGroup : this.grid.ddGroup || 'GridDD'
});
+
}
/*
sortDescText : "Sort Descending",
lockText : "Lock Column",
unlockText : "Unlock Column",
- columnsText : "Columns"
+ columnsText : "Columns",
+
+ columnsWiderText : "Wider",
+ columnsNarrowText : "Thinner"
});