Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
630
Need help in Sorting and formating for the bound coloumn in pivot grid
posted

I am facing the following issues in generating a Pivot grid.
1. Sorting is enabled and it works fine in few cases. It doesn't work for the column headers "Components,Clothing,Bikes.."
I have specified the following attributes, but still the sorting doesn't work on the mentioned columns.
   allowSorting: true,
   allowHeaderRowsSorting: true,
   allowHeaderColumnsSorting: true,
   firstSortDirection: "ascending",
   firstLevelSortDirection: "ascending",

2. How to do the number format for the specified columns "Components,Clothing,Bikes.."
I am not sure how to apply the formating for these columns.

I have attached the code for your reference

Parents
  • 23953
    Offline posted

    Hello,

    If you want sorting feature for the igPivotGrid the custom aggregator is not the way to go. You should use the formatting function of the igGrid like this:

     

    $("#pivotGrid").on("iggridrowsrendering", function (evt, ui) {
    	// return if the column collection is not generated yet
    	if (ui.owner.options.columns && ui.owner.options.columns.length === 0) {
    		return;
    	}
    	for (var i = 0; i < ui.owner.options.columns.length; i++) {
    
    		if (ui.owner.dataSource.data()[0] && $.isNumeric(ui.owner.dataSource.data()[0][ui.owner.options.columns[i].key])) {
    			ui.owner.options.columns[i].formatter = function (val, rec) {
    				if(val > 1000)
    					return "<kbd style="background-color: green;">" + $.ig.formatter(parseFloat(val), "number", "numeric") + "</kbd>";
    				else
    					return "<kbd style="background-color: red; color: white;">" + $.ig.formatter(parseFloat(val), "number", "numeric") + "</kbd>";
    			};
    		}
    	}
    });
    
    

    The code above binds to the igGrid.rowsRendering event and attaches a formatter function for all the columns that are  numeric. Inside the formatter function a styling and formatting is done for the cell value.

    Note: You should put this code before initializing the igPivotGrid.

    Best regards,
    Martin Pavlov
    Infragistics, Inc.

Reply Children