function buildOriginalCache(table) {
			var totalRows, cache;
			totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0,
			cache = {row:[], childrenId:[]};
			var parentId = null;
			var descendantCount;
				
			for (var i=0;i < totalRows; ++i) {
				var c = table.tBodies[0].rows[i], cols = [];
				if (isParent(c)) {
					descendantCount = 0;
					parentId = "parent" + i;
					c.parentId = "parent" + i;
					for(var k=i+1; k<totalRows; k++){
						var b = table.tBodies[0].rows[k];
						if(b.id.match(new RegExp('__hide_division_'))){
							descendantCount = descendantCount + 1;
						}
						else 
							break;
					}
					c.descendantCount = descendantCount;
				}

				if(isDescendant(c)) {
					//Remember its parent
					c.parent = parentId;
					if(isChild(c)){
						//checking siblings after it and identifying them and save row indexes if they are its children 
						var index = c.rowIndex;
						var grandChildrenRows = [];
						var grandChildrenCount = 0;
						var next = index +1;
						var tempRowIndex = i+1;   //It's the array index in originalCacheTable;
												  //Row index in the orginalCacheTable is different with table properties rowIndex
						var row = table.rows[next];
						var leftpadding;
						var paddingDigitValue;    //Relative value without 'em', ex: 2 in '2em';

						//For css style 'padding-left: 1em', firefox returns pixels like 16px or else ; safari and IE returns 1em;
						
						leftpadding = $(row).find("td").eq(1).css("padding-left");
						if(leftpadding != null){
							if(leftpadding.indexOf("px") >= 0){
								var pixels = parseInt(leftpadding.replace("px", ""));
								paddingDigitValue = parseInt($(pixels).toEm().replace("em",""));
							}
							else{
								paddingDigitValue = parseInt(leftpadding.replace("em",""));
							}
 						}						

						//  while (next ) is a grandchild, save the array index in the originalCacheTable for the row;
						while(paddingDigitValue > 1){
							grandChildrenCount++;
							grandChildrenRows.push(tempRowIndex);
							next = next + 1;
							tempRowIndex = tempRowIndex +1;
							if(next < table.rows.length){
								row = table.rows[next];
								leftpadding = $(row).find("td").eq(1).css("padding-left");
								if(leftpadding.indexOf("px") >= 0){
									var pixels = parseInt(leftpadding.replace("px", ""));
									paddingDigitValue = parseInt($(pixels).toEm().replace("em",""));
								}
								else{
									paddingDigitValue = parseInt(leftpadding.replace("em",""));
								}
							}else{
								paddingDigitValue = -1;
							}
						} //end of while loop
						c.grandChildrenCount = grandChildrenCount;
						c.grandChildrenRows = grandChildrenRows;
					}// end of isChild
				}//end of isDescendant
				cache.row.push($(c));
			}; //end of first for loop
			return cache;
		}
/* get original table cache before it's sorted to 
		   record and mark the parent/desendant relationship in each row.
		   Need to remember row index for the children of each children node  */
get original table cache before it's sorted to
record and mark the parent/desendant relationship in each row.
Need to remember row index for the children of each children node
get original table cache before it ' s sorted to record and mark the parent / desendant relationship in each row . Need to remember row index for the children of each children node
function buildOriginalCache(table) {
			var totalRows, cache;
			totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0,
			cache = {row:[], childrenId:[]};
			var parentId = null;
			var descendantCount;
			for (var i=0;i < totalRows; ++i) {
				var c = table.tBodies[0].rows[i], cols = [];
				if (isParent(c)) {
					descendantCount = 0;
					parentId = "parent" + i;
					c.parentId = "parent" + i;
					for(var k=i+1; k<totalRows; k++){
						var b = table.tBodies[0].rows[k];
						if(b.id.match(new RegExp('__hide_division_'))){
							descendantCount = descendantCount + 1;
						}
						else 
							break;
					}
					c.descendantCount = descendantCount;
				}
				if(isDescendant(c)) {
					c.parent = parentId;
					if(isChild(c)){
						var index = c.rowIndex;
						var grandChildrenRows = [];
						var grandChildrenCount = 0;
						var next = index +1;
						var tempRowIndex = i+1;   
						var row = table.rows[next];
						var leftpadding;
						var paddingDigitValue;    
						leftpadding = $(row).find("td").eq(1).css("padding-left");
						if(leftpadding != null){
							if(leftpadding.indexOf("px") >= 0){
								var pixels = parseInt(leftpadding.replace("px", ""));
								paddingDigitValue = parseInt($(pixels).toEm().replace("em",""));
							}
							else{
								paddingDigitValue = parseInt(leftpadding.replace("em",""));
							}
 						}						
						while(paddingDigitValue > 1){
							grandChildrenCount++;
							grandChildrenRows.push(tempRowIndex);
							next = next + 1;
							tempRowIndex = tempRowIndex +1;
							if(next < table.rows.length){
								row = table.rows[next];
								leftpadding = $(row).find("td").eq(1).css("padding-left");
								if(leftpadding.indexOf("px") >= 0){
									var pixels = parseInt(leftpadding.replace("px", ""));
									paddingDigitValue = parseInt($(pixels).toEm().replace("em",""));
								}
								else{
									paddingDigitValue = parseInt(leftpadding.replace("em",""));
								}
							}else{
								paddingDigitValue = -1;
							}
						} 
						c.grandChildrenCount = grandChildrenCount;
						c.grandChildrenRows = grandChildrenRows;
					}
				}
				cache.row.push($(c));
			}; 
			return cache;
		}
function buildOriginalCache ( table ) { var totalRows , cache ; totalRows = ( table . tBodies [ 0 ] && table . tBodies [ 0 ] . rows . length ) || 0 , cache = { row : [ ] , childrenId : [ ] } ; var parentId = null ; var descendantCount ; for ( var i = 0 ; i < totalRows ; ++ i ) { var c = table . tBodies [ 0 ] . rows [ i ] , cols = [ ] ; if ( isParent ( c ) ) { descendantCount = 0 ; parentId = "parent" + i ; c . parentId = "parent" + i ; for ( var k = i + 1 ; k < totalRows ; k ++ ) { var b = table . tBodies [ 0 ] . rows [ k ] ; if ( b . id . match ( new RegExp ( '__hide_division_' ) ) ) { descendantCount = descendantCount + 1 ; } else break ; } c . descendantCount = descendantCount ; } if ( isDescendant ( c ) ) { c . parent = parentId ; if ( isChild ( c ) ) { var index = c . rowIndex ; var grandChildrenRows = [ ] ; var grandChildrenCount = 0 ; var next = index + 1 ; var tempRowIndex = i + 1 ; var row = table . rows [ next ] ; var leftpadding ; var paddingDigitValue ; leftpadding = $ ( row ) . find ( "td" ) . eq ( 1 ) . css ( "padding-left" ) ; if ( leftpadding != null ) { if ( leftpadding . indexOf ( "px" ) >= 0 ) { var pixels = parseInt ( leftpadding . replace ( "px" , "" ) ) ; paddingDigitValue = parseInt ( $ ( pixels ) . toEm ( ) . replace ( "em" , "" ) ) ; } else { paddingDigitValue = parseInt ( leftpadding . replace ( "em" , "" ) ) ; } } while ( paddingDigitValue > 1 ) { grandChildrenCount ++ ; grandChildrenRows . push ( tempRowIndex ) ; next = next + 1 ; tempRowIndex = tempRowIndex + 1 ; if ( next < table . rows . length ) { row = table . rows [ next ] ; leftpadding = $ ( row ) . find ( "td" ) . eq ( 1 ) . css ( "padding-left" ) ; if ( leftpadding . indexOf ( "px" ) >= 0 ) { var pixels = parseInt ( leftpadding . replace ( "px" , "" ) ) ; paddingDigitValue = parseInt ( $ ( pixels ) . toEm ( ) . replace ( "em" , "" ) ) ; } else { paddingDigitValue = parseInt ( leftpadding . replace ( "em" , "" ) ) ; } } else { paddingDigitValue = - 1 ; } } c . grandChildrenCount = grandChildrenCount ; c . grandChildrenRows = grandChildrenRows ; } } cache . row . push ( $ ( c ) ) ; } ; return cache ; }
get original table cache before it's sorted to
record and mark the parent/desendant relationship in each row.
get original table cache before it ' s sorted to record and mark the parent / desendant relationship in each row .
//Remember its parent //checking siblings after it and identifying them and save row indexes if they are its children  //It's the array index in originalCacheTable; //Row index in the orginalCacheTable is different with table properties rowIndex //Relative value without 'em', ex: 2 in '2em'; //For css style 'padding-left: 1em', firefox returns pixels like 16px or else ; safari and IE returns 1em; //  while (next ) is a grandchild, save the array index in the originalCacheTable for the row; //end of while loop // end of isChild //end of isDescendant //end of first for loop