Qooxdoo Set Column Width to Fill Table - qooxdoo

I have a Table with 3 columns, the left 2 are fixed-width. I am trying to make the third column fill the whole remaining table.
I have tried:
logTable.getTableColumnModel().set(2, {flex: 1});
But this did nothing to the column width.
Thanks in advance!

The default table column model does not allow that, but the Resize table column model, `qx.ui.table.columnmodel.Resize, does. You can do something like this:
var table = new qx.ui.table.Table(
tableModel, // previously defined, with 3 columns
{
// We want to handle the behavior of table column resizing
tableColumnModel : function(obj)
{
return new qx.ui.table.columnmodel.Resize(obj);
}
});
// Use the Resize table column model to allow final column to consume
// remainder of space
var tcm = table.getTableColumnModel();
var resizeBehavior = tcm.getBehavior();
resizeBehavior.setWidth(0, 50);
resizeBehavior.setWidth(1, 140);
resizeBehavior.setWidth(2, "1*");
Enjoy.
Derrell

Related

Adding a custom "ALL" (Total) row to the top of an ag-grid that is selectable like any other row

I have an ag-grid table with 2 columns - one text and one number.
I need to add a custom row to the top of my ag-grid table with the total value of the number column and the word "ALL" in the text column.
This needs to be on the top. And should not change its position even if the table is sorted.
Also, the row should be selectable.
Any help in this regard will be highly appreciated!
Sounds like you are describing Row Pinning which is already a feature in AG Grid. However, since you've also stated that row selection is a requirement, this will not be possible with Row Pinning as it's not supported.
Instead what I'd recommend is adding an extra row object inside the rowData for the custom row, and handling the update of the number column and the custom row position yourself when necessary:
If you want to handle the total value of the number column then you can use the following logic:
function updateTotalRowNode() {
let totalRowNode;
let sum = 0;
gridOptions.api.forEachNode((node) => {
if (node.data.totalRow) {
totalRowNode = node;
} else {
sum += node.data.gold;
}
});
totalRowNode.setDataValue('gold', sum);
}
If you want to keep the custom row always on the top row then you can implement the postSort callback:
postSort: (rowNodes) => {
// here we put All row on top while preserving the sort order
let nextInsertPos = 0;
for (let i = 0; i < rowNodes.length; i++) {
const athlete = rowNodes[i].data.athlete;
if (athlete === 'All') {
rowNodes.splice(nextInsertPos, 0, rowNodes.splice(i, 1)[0]);
nextInsertPos++;
}
}
},
See the following plunker for the implementation.

Comparing multiple values in Google Sheets with App Script for loops

I would like to compare multiple values in a Google Sheet spreadsheet some using for loops in Google App Script. But i would like some advice on the best way to do it.
To explain below...
I have two spreadsheets, A "FOOD" table, and A "FOOD GROUP" table. 
I've written a for loop script that goes through the entire FOOD table.
If the key value of both tables matches, the script will update a column from the FOOD table with a column from the FOOD GROUP table.
The script works without issues. But it can only compare one column between the 2 tables at a time. I would like to modify this script so I can compare multiple columns at once, without having to create a for loop for each specified column.
I pasted my code below. I can also provide images of my spreadsheet if you need it. 
In any case, I'm new to coding, so any constructive feedback or insight to improve my script will be helpful. I'm happy to answer any questions if anything seems unclear.
function FoodGroup_Test() {
var Data = SpreadsheetApp.getActiveSpreadsheet();
var FoodGroupDataSheet = Data.getSheetByName("Food Groups") // "FoodGroup" sheet
var FoodGroupAllValues = FoodGroupDataSheet.getRange(2, 1, FoodGroupDataSheet.getLastRow()-1,FoodGroupDataSheet.getLastColumn()).getValues();
var FoodGroupDataLastRow = FoodGroupDataSheet.getLastRow();
var FoodDataSheet = Data.getSheetByName("Food") // "Food" sheet
var FoodAllValues = FoodDataSheet.getRange(2, 1, FoodDataSheet.getLastRow()-1,FoodDataSheet.getLastColumn()).getValues();
// Object to contain all FoodGroup column values
var Object = {};
for(var FO = FoodGroupAllValues.length-1;FO>=0;FO--) // for each row in the "FoodGroup" sheet...
{
Object[FoodGroupAllValues[FO][15]] = FoodGroupAllValues[FO][11]; // ...store FoodGroup ID Key value
}
for(var F = FoodAllValues.length-1;F>=0;F--) // for each row in the "Food" sheet...
{
var Food_FoodGroupKey = FoodAllValues[F][94]; // Store FoodGroup Key value.
// ...if the Food value dont match, update it with FoodGroup's value
if (Object[Food_FoodGroupKey] != FoodAllValues[F][95])
{
FoodAllValues[F][95] = Object[Food_FoodGroupKey];
}
}
// declare range to place updated values, then set it.
var FoodDestinationRange = FoodDataSheet.getRange(2, 1, FoodAllValues.length, FoodAllValues[0].length);
FoodDestinationRange.setValues(FoodAllValues);
}
FOOD GROUP Table
FOOD table
In order for your code to work as expected, you should do the following changes to your code:
Update your if condition to this one:
Object[Food_FoodGroupKey] != FoodAllValues[F][95] && object2[] != FAllValues[F][86])
In order to avoid the undefined problem use the following line of code:
FoodDataSheet.createTextFinder("undefined").replaceAllWith("");

ag-Grid: use floatingBottomRowData when Pivoting

I'm trying to recreate the following pivot table with ag-Grid:
Using floatingBottomRowData I can't find a way to pass the values for all generated columns. so one pair of values is getting duplicated:
My goal is to access the column group value for each cell of the floating row.
Right now I can't tell the difference between column groups (resulting in duplicated values).
Is there any way to differentiate the different (col1, col2) pairs?
The answer that was given in the ag-grid forum is:
to get the pivot key, do this:
floatingCellRenderer: function(params) {
if (gridOptions.columnApi.isPivotMode()) {
console.log(params.column.getId());
var parent = params.column.getParent();
if (parent) {
var pivotKey = console.log(parent.getOriginalColumnGroup().getColGroupDef().pivotKeys[0]);
}
}
}
to get the columns in the active pivot, use the column API, eg columnApi.getPivotColumns(), which will return a list of the pivot columns. this will be in order, so if you have many columns, there will be one for each parent you traverse.
What I did for the pivot_ type of pinned row: I added a custom pinned row renderer to my column, where I expect the aggregated function to show (for me it was for sum and avg). If I change the pivot function I called a refresh on the pinned row to set the new values.
pinnedRowCellRenderer: function (render)
{
for (var obj_id in render.data)
{
if (obj_id == render.column.colId)
{
return '<div>' + render.data[obj_id] + '</div>';
}
}
return '<div></div>';
}
And the result looks like this:
Result image
Hope it helps!

Programmatically change grid column order

I want to sort the columns in my grid, just like the rows. I have made a simple sort function that is called from an actioncolumn handler:
sortColumns:function(record) { // The record after which's values the columns are ordered
var columns = this.columns;
Ext.Array.sort(columns,function(col1,col2) {
if(record.get(col1.dataIndex) > record.get(col2.dataIndex)) return 1;
if(record.get(col1.dataIndex) < record.get(col2.dataIndex)) return -1;
if(col1.dataIndex > col2.dataIndex) return 1;
if(col1.dataIndex < col2.dataIndex) return 1;
throw new Error("Comparing column with itself shouldn't happen.");
});
this.setColumns(columns);
});
The setColumns line now throws the error
Cannot add destroyed item 'gridcolumn-1595' to Container 'headercontainer-1598'
which is because the "old" columns are destroyed first, and then the "new" columns, which are the same and thus destroyed, are applied.
I only want to change the order, but I didn't find any function to do it. Do you know how to do it?
Drag-drop ordering of the columns works, so it is doable; but I don't find the source code where sencha did implement that drag-drop thingy. Do you know where to look for that code?
Reconfigure method needs two arguments
grid.reconfigure(store, columns)
Here is the fiddle that changes the columns programatically https://fiddle.sencha.com/#fiddle/17bk
I have found that columns are items of the grid's headerCt, so the following works well, and unlike the other answers, it does not create new column components, keeping the column state and everything:
var headerCt = normalGrid.headerCt,
columns = headerCt.items.getRange();
Ext.Array.sort(columns,function(col1,col2) {
if(record.get(col1.dataIndex) < record.get(col2.dataIndex)) return -1;
if(record.get(col1.dataIndex) > record.get(col2.dataIndex)) return 1;
if(col1.dataIndex < col2.dataIndex) return -1;
if(col1.dataIndex > col2.dataIndex) return 1;
return 0;
});
headerCt.suspendLayouts();
for(var i=0;i<columns.length;i++)
{
headerCt.moveAfter(columns[i],(columns[i-1] || null));
}
headerCt.resumeLayouts(true);
There is a reconfigure method which can be used to achieve reordering, e.g:
grid.reconfigure(columns);
Check the this.
I couldn't manage to do it without storing columns in a custom field and using reconfigure, maybe someone can suggest something better (reconfigure doesn't work well with just regular columns field it seems):
Ext.define('MyGrid', {
extend: 'Ext.grid.Panel',
//just renamed "columns"
myColumnConfigs: [
//all your column configs
]
});
//to rearrange inside controller, also need to call it on grid render
var grid = this.getView();
var columns = grid.myColumnConfigs;
//...do your sorting on columns array
grid.reconfigure(columns);

Infragistics Grid ColumnFilter filtering based on 2 column values

I have 2 columns x and Y. I need to filter grid based on values of 2 columns.
For example: Suppose my filter condition is true, then it should check the value of both the columns and if any of the column value is true it should not filter the row. If none of the value is true than the row should be filtered.
I can think of one quick solution for this. The below code will set normal filters on 2 columns, then you just change the columns LogicalOperator.
private void Filter() {
Infragistics.Win.UltraWinGrid.FilterCondition fc = new Infragistics.Win.UltraWinGrid.FilterCondition();
fc.CompareValue = "someValue1";
fc.ComparisionOperator = Infragistics.Win.UltraWinGrid.FilterComparisionOperator.Equals;
ultraGrid1.DisplayLayout.Bands[0].ColumnFilters["col_x"].FilterConditions.Add(fc);
Infragistics.Win.UltraWinGrid.FilterCondition fc2 = new Infragistics.Win.UltraWinGrid.FilterCondition();
fc2.CompareValue = "someValue2";
fc2.ComparisionOperator = Infragistics.Win.UltraWinGrid.FilterComparisionOperator.Equals;
ultraGrid1.DisplayLayout.Bands[0].ColumnFilters["col_y"].FilterConditions.Add(fc2);
// set the logical operator of the columns on the band
ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.LogicalOperator = Infragistics.Win.UltraWinGrid.FilterLogicalOperator.Or;
}
Is this what you were looking for?

Resources