Hi there,
I am trying to include igPivot and related functions into one of my projects. For further usage, I need an unique ID for each cell of a pivot. I am using a flat file source and I have found a key so far. But the syntax "Axis0_0_0_false" doesn't mean anything to me. I would need an identifier consisting of the dimension name and value. For example if I have countries (US, UK, Total) as rows and status (A, B, C) as columns with a measure "sales", the unique cell identifier could be something like
[Country:US, Status:A, Measure:Sales]
or
[Country:Total, Status:C, Measure:Sales]
Is there a way to include this as ID of the TD-Tags?
Thanks and best regards
Florian
//here you go
function getCellAccountForSpans(cells, idx){ var upTo = 0; for(var i=0;i<cells.length;i++){ var colSpan = $(cells[i]).attr("colspan"); if(colSpan != null){ upTo += parseInt(colSpan); }else{ upTo += 1; } if(upTo > idx){ return cells[i]; } } return null;}
Hi John,
Thanks for the reply, your code gets me closer. However, I think you missed posting the function getCellAccountForSpans(), I am getting a reference error. Can you post that as well?
Regards,
Pak
Here was my solution - it sets the id of the table cell = to the filter as defined by the row/column headers. I call it in the pivotGridRendered() callback.
pivotGridRendered: function(evt, ui){
setTimeout($scope.setCellIDs());
}
$scope.setCellIDs = function() { var grid = $(element).find(":ui-igPivotGrid").igPivotGrid("grid"); var rows = grid.rows(); //get the measure element and get its title. var measure = $("#"+$scope.pivotId+"_pivotGrid_measures").find("li").attr("title"); var headerRowCells = $("tr[data-header-row]").find("th"); var headerRows = $("tr[data-mch-level]"); var xCategories = $("ul[data-role=columns].ui-widget-content").find("li"); if(headerRows.length > 0) { var colOneDimensions = $(headerRows[0]).find("li"); }else{ var colOneDimensions = $(headerRowCells[0]).find("li"); } //loop in the rows cellOffsetDueToColSpans = 0; colSpanRowAffected = {}; colAffected = {}; var prevYDim = {}; for (var rowIdx = 0; rowIdx < rows.length; rowIdx++) { var row = rows[rowIdx]; if(colSpanRowAffected[rowIdx] == null){ collOffsetDueToColSpans = 0; prevYDim = {}; } //Find the left-most (row-level) filter var yDims = []; //1st column filters var yDimCells = $(row).find("th"); for(var i = 0; i< colOneDimensions.length; i++){ var yDimCellIdx = i - (colSpanRowAffected[rowIdx] != null?cellOffsetDueToColSpans:0); if(yDimCellIdx != i && colAffected[i] != null){ yDims[i] = prevYDim[i]; continue; } if(yDimCells.length >= yDimCellIdx) { var yDimCell = yDimCells[yDimCellIdx]; if($(yDimCell).attr("rowspan") != null) { var numRows = parseInt($(yDimCell).attr("rowspan")); if(numRows > 1) { cellOffsetDueToColSpans += 1; for (var j = 1; j < numRows; j++) { colSpanRowAffected[rowIdx + j] = true; colAffected[i] = true; } prevYDim[i] = { name: colOneDimensions[i].title.toLowerCase(), value: yDimCell.title}; } } yDims.push( { name: colOneDimensions[i].title.toLowerCase(), value: (yDimCell ? yDimCell.title : '')}); } } //get all cells in the current row var cells = $(row).find("td"); var cellOffsetDueToRowSpans = 0; var rowSpanRowAffected = -1; for (var cellIdx = 0; cellIdx < cells.length; cellIdx++) { var cell = cells[cellIdx]; var xDims = []; //get the header row cells. //get the name of the row dimension from the header row /** if no columns are expanded, this path comes through */ if(headerRowCells.length > 0) { //yDims[0] = {name: $(headerRowCells[0]).find("li").attr("title"), value: dimentionYRow}; var colHeaderEl = $("#"+$scope.pivotId+"_pivotGrid_columns").find("li"); xDims[0] = { name: colHeaderEl.length == 0?"":colHeaderEl.attr("title").toLowerCase(), value: $(headerRowCells[cellIdx + 1]).attr("title") }; }else{ //Reverse iterate through data-mch-level rows var handledAxisSet={}; for(var headerRowIdx = headerRows.length - 1; headerRowIdx >= 0; headerRowIdx--){ var hRow = headerRows[headerRowIdx]; var hCell = getCellAccountForSpans($(hRow).find("th[role=rowheader]"),cellIdx - (rowSpanRowAffected == headerRowIdx?cellOffsetDueToRowSpans:0)); //Account for 1st col header if(hCell == null){ continue; } var axis = parseInt($(hCell).attr("data-member")); if($(xCategories[axis]).attr("data-type") == "MeasureList"){ //This is a Measurement header (i.e. qty or value). No filter applies continue; } var expandCell = $(hCell).find("span"); if(expandCell.length > 0){ if($(expandCell[0]).attr("data-expand") == "false"){ continue; //This is a top-level category that was expanded. Values in lower cells }else{ if($(hCell).attr("rowspan") != null){ cellOffsetDueToRowSpans += 1; rowSpanRowAffected = headerRowIdx+1; } } } //See if this axis was already handled if(handledAxisSet[axis] != null){ continue; } xDims.push({ name: xCategories[axis].title.toLowerCase(), value: hCell.title }); handledAxisSet[axis] = true; } } var id = ""; for(var i=0;i<xDims.length;i++){ if(xDims[i].name == ""){ continue; } if(i>0){ id += ","; } id += xDims[i].name+":"+xDims[i].value; } for(var i=0;i<yDims.length;i++){ if(id != ""){ id += ","; } id += yDims[i].name+":"+yDims[i].value; } //build the id you want based on the collected data //set the id for each cell. $(cell).attr("id", id); //$(cell).text(id); $scope.pivotStatus = ""; } }}
Hi Florian,
I am looking to do exactly the same thing. Can you share your solution?
Thanks,
I'm facing the same issue - could you post your solution to the forum?