CodeThatGrid - Hide columns/rows names, user-defined functions

CodeThatGrid - Hide columns/rows names, user-defined functions

| | |

<script language="javascript1.2">
<!--
//DEFINE USER FUNCTIONS
function subTotal(g, cell) {
	if (Undef(cell)) return;
	var c0 = g.getColByTitle('Price'),
	c1 = cell.col._id, //Quantity
	c2 = g.getColByTitle('Subtotal'),
	c3 = g.getColByTitle('Discount'),
	r = cell.row._id, t;
	if (c1 == c2) return;
	g.cells[r][c2].setData(g.cells[r][c0].data*g.cells[r][c1].data*(100 - g.cells[r][c3].data)/100, 0);
	if (g.isInit) g.cells[r][c2].paint();
};

function total(g, cell) {
	if (Def(cell)) {
		//calculate  total across current column
		if (g.cells[g.rowCount - 1].length < g.cols.length) return;
		var c = cell.col, i, j, s = 0;
		if (c.type != 'Number' && c.type != 'Currency') return; // no calculations
		for (i = 0; i < g.rowCount - 1; i++) s += g.cells[i][c._id].data;
		g.cells[g.rowCount - 1][c._id].data = s;
		if (g.isInit) g.cells[g.rowCount - 1][c._id].paint();
	}
	else{
		//initialization with start calculate values
		var i, j, c = g.getColByTitle('Quantity');
		g.isInit = 0; 	 //flag that data is not load yet
		g.addRow(g.rowCount, 0, 0); 	//create result row
		g.rows[g.rowCount - 1].isReadOnly = 1; //make it read only
		for (i = 0; i < g.colCount; i++) {
			g.cells[g.rowCount - 1][i].b = "bold"; //make cells in result row bold
			for (j = 0; j < g.rowCount - 1; j++) {
				if (i == c) subTotal(g, g.cells[j][i]); //calculate subtotal
				total(g, g.cells[j][i]); //calculate total
				g.rows[j].userFunction = subTotal; //set userFunction for each row
			};
		};
		g.isInit = 1; //flag that data loaded
		g.paint();
	};
};
//DEFINE USER TYPE DISCOUNT
var DISCOUNT_FORMAT = "%";
function parseDiscount(numVal) {
	return parseNumber(numVal);
};

function formatDiscount(numObj, formatDiscount) {
	return (numObj > 0) ? formatDiscount + " " + numObj : DEFAULT_RESULT;
};
//REDIFEINE TYPE NUMBER
function parseNumber(numVal) {
	if (Undef(numVal)) return 0;
	numVal = new String(numVal);
	numVal = parseFloat(numVal.replace(/[^0 - 9-\ + \..]/ig, ''));
	if (isNaN(numVal) || numVal < 0) return - 1
	else return new Number(numVal);
};
//REDIFEINE TYPE CURRENCY
function parseCurrency(curVal) {
	if (Undef(curVal)) return 0;
	curVal = new String(curVal);
	curVal = parseFloat(curVal.replace(/, /, '.').replace(/[^0 - 9-\ + ]/ig, ''));
	if (isNaN(curVal) || curVal < 0) return 0
	else return new Number(curVal);
};
//FORMAT CURRENCY AS '$ 0.00'
function formatCurrency(curObj, formatCurrency) {
	if (Undef(curObj)) return DEFAULT_RESULT;
	return formatCurrency + " " + Math.round(curObj*100)/100;
};
//GRID DEFINITION
var gridDef = {
	amountPerPage : 1000,
	useRCID : 0,
	useProgress : 0,
	tableStyle : {
		width : '100%', height : 200
	},
	statusBar : {
		height : 0
	},
	toolBar : {
		height : 0
	},
	datatype : 0,
	data : [[1, 20, 'Bast-basket', 1, 10.25, 1],
	[2, 10, 'Darts', 1, 9.99, 0],
	[3, 1, 'Petards', 8.7, 4, 0],
	[4, 3, 'Tubule', 3.35, 9, 3],
	[5, 4, 'Butterfly net', 5, 10, 0.5],
	[6, 12, 'Chinese lantern', 10, 2, 10],
	[11, 13, 'Aquarium', 3, 4, 0],
	[7, 14, 'Handbag', 1, 10.01, 0]
	],
	userFunction : total,
	colDef : [
	{
		title : 'ID',
		type : 'String',
		isReadOnly : 1,
		isVisible : 0,
		width : 0
	},
	{
		title : 'Item No',
		type : 'String',
		isReadOnly : 1,
		isVisible : 1,
		width : 50
	},
	{
		title : 'Item',
		type : 'String',
		isReadOnly : 1,
		isVisible : 1,
		width : 300
	},
	{
		title : 'Quantity',
		type : 'Number',
		isReadOnly : 0,
		isVisible : 1,
		width : 80,
		alignment : 'right'
	},
	{
		title : 'Price',
		type : 'Currency',
		isReadOnly : 1,
		isVisible : 1,
		width : 100,
		alignment : 'center'
	},
	{
		title : 'Discount',
		type : 'Discount',
		isReadOnly : 1,
		isVisible : 1,
		width : 80,
		alignment : 'center'
	},
	{
		title : 'Subtotal',
		type : 'Currency',
		isReadOnly : 1,
		isVisible : 1,
		width : 100,
		alignment : 'right'
	} ]
}; 
//-->
</script>