Cette réponse suppose que vous ayez accès au code.
Vous pouvez accéder à l'API si vous avez le contrôle du fichier gridOptions
. Une fois la grille initialisée, c'est-à-dire après l'exécution de cette ligne
new agGrid.Grid(eGridDiv, gridOptions);
Il adopte gridApi
y columnApi
à votre gridOptions
. Vous pouvez commencer à manipuler le tableau comme bon vous semble. Voici un petit exemple
// at this point you don't have accesss to the API yet
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData,
};
var eGridDiv = document.querySelector('#myGrid');
// initialize ag-grid
new agGrid.Grid(eGridDiv, gridOptions);
// grid APIs are ready, we can print current column state for example
console.log(gridOptions.columnApi.getColumnState());
setTimeout(() => {
var sort = [
{ colId: 'price', sort: 'desc' },
];
gridOptions.api.setSortModel(sort);
}, 2000)
Voir la démonstration en direct aquí
Référence