Reputation: 211
I am using a method per ag-grid example setting
gridOptions = {
columnDefs: [],....etc.
and reading a json file from the server that populates the fields (and columns).
// Get data from server //https://ag-grid.com/javascript-data-grid/getting-started/
fetch ('https://dev.perfectiononwheels.com/pricedataJSON/pricelistJson.json')
.then(function (response) {
return response.json();
}).then(function (data) {
// set the column headers from the data
const colDefs = gridOptions.api.getColumnDefs();
colDefs.length=0;
const keys = Object.keys(data[0])
keys.forEach(key => colDefs.push({field : key}));
gridOptions.api.setColumnDefs(colDefs);
// add the data to the grid
gridOptions.api.setRowData(data);
});
The document states that using this technique you can then set editable:true to be able to edit fields on the grid. However, I would like to set some columns (fields) as read-only, and change another to a checkbox.
I am not able to find an refernce on how to access a column to change to read-only or a checkbox. (I was able to set these params when I defined each field in the columnDefs)
Upvotes: 1
Views: 2597
Reputation: 111
If you want to use a regular text selection as if the grid were a regular table, set enableCellTextSelection=true and ensureDomOrder=true in the gridOptions.
Upvotes: 0
Reputation: 30088
There is no direct api for this.
To change whether a column is editable, you'll have to change the editable
property for the column in the columnDefs, and then call the grid api's setColumnDefs()
method, passing it the updated columnDefs.
Same thing with the checkboxSelection
property, to show a checkbox or not.
Upvotes: 1