AG-Grid FillHandle Increment Value Cross Row Groups - ag-grid

Example at https://plnkr.co/edit/0CPdb8dXPCafCJjI
const gridOptions = {
columnDefs: [
{ field: 'athlete',
minWidth: 150,
rowGroup: true,
hide: true, },
{ field: 'year', maxWidth: 90 },
],
defaultColDef: {
flex: 1,
minWidth: 100,
editable: true,
},
enableRangeSelection: true,
enableFillHandle: true,
fillHandleDirection: "y",
groupDisplayType: "groupRows",
groupDefaultExpanded: 1,
};
Grid has row groups. Selecting 2004, holding down "alt" and dragging down increases the value in column "Year" as intended. The issue comes when dragging over to a new group. I would like first row for "Natalie Coughlin" to be 2006, but it seems like AG grid is counting group row header as a regular row.
Anyone know how to accomplish this?

Related

Ag-grid Master/Detail grid Independent pagination at Master and Detail

if number of rows of detail grid are more, it is tedious to scroll through all rows,
Is it possible to add pagination at Master and Detail independently?
I have gone through the below link of ag-grid documentation but did not find a way or mention of pagination.
https://www.ag-grid.com/javascript-grid-master-detail/
You just need to add pagination related properties pagination : true to the detail grid options. Here is what your detailGridOptions would look like -
this.detailCellRendererParams = {
detailGridOptions: {
columnDefs: [
{ field: 'callId' },
{ field: 'direction' },
{
field: 'number',
minWidth: 150,
},
{
field: 'duration',
valueFormatter: "x.toLocaleString() + 's'",
},
{
field: 'switchCode',
minWidth: 150,
},
],
defaultColDef: { flex: 1 },
pagination : true, //set pagination to true
paginationPageSize: 5 // define page size, default is 100
},
getDetailRowData: function(params) {
params.successCallback(params.data.callRecords);
},
};
}
Attaching the example screenshot -
Used this example

Tree Data: Possible to use a Column Group Definition as autoGroupColumnDef

I tried to use a column group as autoGroupColumnDef as I want the the header to be in the top row aligned with other top headers. When I do this the header is rendered in the "sub header" row and the innerRenderer is not used. Anyone knows if it's possible to get this to work?
The column group looks like this.
headerName: 'Group header',
children: [{
headerName: '',
suppressMovable: true,
suppressSizeToFit: true,
pinned: 'left',
field: 'name',
minWidth: 200,
sort: 'asc',
cellRendererParams: {
suppressCount: true,
innerRenderer: 'myCustomRenderer',
}
}]
} as ColGroupDef

Bind ag-grid with array

I have an array with values array=[3,4].I have to display the ag-grid values if it matches with array values.This is what i tried so far:
Attached is the plunkr :https://plnkr.co/edit/fKrvfzFYjdLbTLjFkqpY?p=preview
var array=[3,4];
var columnDefs = [
{headerName: "Jobs",field: "job", width: 90},
{headerName: "Location", field: "loc", width: 120 },
{headerName: "Value", field: "value", width: 120 }];
var rowData =[{job:'Developer',loc:'X',value:1},
{job: 'Manager',loc:'Y',value:2},
{job: 'Musician',loc:'Z',value:3},
{job: 'Manager',loc:'A',value:4},
{job: 'Tester',loc:'B',value:5},
{job: 'DBA',loc:'C',value:6}
];
var gridOptions = {
defaultColDef: {
sortable: true
},
columnDefs: columnDefs,
animateRows: true,
enableRangeSelection: true,
rowData: rowData,
checkbox : true
};
How to display the grid when value field value matches with array values.
Here is a plunkr with a working example - https://plnkr.co/edit/xdwI0Tql9I5n71D4QSDy?p=preview
Add a custom cellRenderer function like so in the column definition of values column
{
headerName: "Value",
field: "value",
width: 120,
cellRenderer: params => array.includes(params.value) ? params.value : ''
}

Radio Buttons in ag-grid

I am using ag-grid to display my data and i have below question:
1.Instead of check boxes i want radio buttons to be displayed when i expand the group and also my grouping is not working as expected.?
Plunkr link for the above grid what i tried so far https://plnkr.co/edit/KahAzPv6QEccaaRKlzCN?p=preview
var gridOptions = {
columnDefs: [
{headerName: "Jobs",field: "job", width: 90,rowGroupIndex: 0 ,hide:true},
// this tells the grid what values to put into the cell
//showRowGroup: 'position'
// this tells the grid what to use to render the cell
// cellRenderer:'agGroupCellRenderer'
//{field: 'position', rowGroup: true, hide: true},
{headerName: "Name", field: "name"}
],
rowData: [
{position:'Developer',name:'Test1',job:'Position'},
{position: 'Manager', name:'Test2',job:'Position'},
{position: 'Musician',job:'Position'},
{position: 'Manager',name:'Test4',job:'Position'},
{position: 'Europe',job:'Location'},
{position: 'Australia',name:'Test4',job:'Location'}
],
/* autoGroupColumnDef:{
headerName:'',
cellRendererParams:{
suppressCount: true,
checkbox:true
}
}*/
autoGroupColumnDef: {
headerName: "Jobs",
field: "position",
width: 250,
cellRenderer:'agGroupCellRenderer',
cellRendererParams: {
checkbox: true
}
}
};

How to hide column in AG-Grid?

How to hide the column in AG-Grid and also it should not be displayed in Tool Panel...
var columnDefs = [{ headerName: "Stone_ID", field: "Stone_ID", width: 100, hide: "true" }]
You can set the column property of suppressToolPanel to true to achieve that.
var columnDefs = [
{
headerName: "Stone_ID",
field: "Stone_ID",
width: 100,
hide: true,
suppressToolPanel: true
}
]
If you are looking for dynamically show/hide columns follow below:
You can use either setColumnVisible or setColumnsVisible.
NOTE: those functions expect a colKey(s) which is related to the field you set in columnDefs.
columnDefs = [
{
headerName: "Name",
field: "name", // => that!
width: 150
},
{
headerName: "Last Name",
field: "last_name", // => that!
width: 150
},
// ...
];
When using setColumnVisible you can show/hide a single column
gridOptions.columnApi.setColumnVisible('name', false) //In that case we hide it
When using setColumnsVisible you can show/hide multiple columns
gridOptions.columnApi.setColumnsVisible(['name', 'last_name'], true) //In that case we show them
To do this programatically you can use:
Hide columns:
this.agGrid.columnApi.setColumnsVisible(["COL_ID_1", "COL_ID_2"], false);
Show columns:
this.agGrid.columnApi.setColumnsVisible(["COL_ID_1", "COL_ID_2"], true);
To do this for a whole column group you can use:
const group = this.columnApi.getColumnGroup("MY_GROUP");
group.children.forEach(child => this.columnApi.setColumnsVisible(child, false));
Posting late but It may helpful for others with some extra details:
If you want to hide your column on the grid you can use hide property to hide that column from the grid.
Only hide from grid colDef example:
colMainDef = [
{
headerName: 'Approved',
field: 'status',
hide: true
}]
But the same column will still be accessible on the side menu panel if you want to hide it from the side menu you can use one more property suppressColumnsToolPanel by making this true it will hide the column from the side menu.
Hide column from the grid as well as from side panel colDef example:
colMainDef = [
{
headerName: 'Approved',
field: 'status',
suppressColumnsToolPanel: true,
hide: true,
}]
Hope this will helps to hide/show columns as per your requirements.
var columnDefs = [{ headerName: "Stone_ID", field: "Stone_ID", width: 100, hide: true }]
{
...,
hide: true,
suppressColumnsToolPanel: true
}
In the package.json:
"dependencies": {
"#ag-grid-community/angular": "^24.1.0",
"#ag-grid-enterprise/all-modules": "^24.1.0",
...
}
hide: should get the value true, not the string "true" (like width: gets 100, not "100")
Just add "hide: true" in your column definition.
Ex:
var columnDefs = [{ headerName: "ABC", field: "XYZ", hide: true }]
hide column on load
{
headerName: 'ROE',
field: 'roe',
width: 100,
hide: true
},
based on selection you can show/hide it using
example
this.gridColumnApi.setColumnVisible('roe',true);
We can hide column dynamically in the following way using onColumnVisible listen event
const onColumnVisible = useCallback(params => {
if (params.source === 'toolPanelUi') {
const colId = params.column ? [ params.column.colId ] : params.columns.map(col => col.colId)
const value = columns.map(v => {
if (v.colId === colId.find(c => c === v.colId)) {
params.visible ? v.hide = false : v.hide = true
}
return v
})
if (value) {
setColumns(value)
}
}
}, [ gridParams, setColumns ])
<Grid onColumnVisible={onColumnVisible } />