设置栅格只读字段



我正在使用每个ag-grid示例设置的方法

gridOptions = {
columnDefs: [],....etc.

和从服务器读取填充字段(和列)的json文件。

//从服务器获取数据//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);
});

文档指出,使用这种技术,您可以设置edititable:true,以便能够编辑网格上的字段。但是,我想将一些列(字段)设置为只读,并将另一个更改为复选框。

我找不到关于如何访问列以更改为只读或复选框的参考。(当我在columnDefs中定义每个字段时,我能够设置这些参数)

没有直接的api。

要更改列是否可编辑,您必须更改列在columnDefs中的editable属性,然后调用grid api的setColumnDefs()方法,将更新的columnDefs传递给它。

checkboxSelection属性相同,以显示复选框或不。

如果你想使用一个普通的文本选择,如果网格是一个普通的表,设置enableCellTextSelection=true和ensureDomOrder=true在gridOptions

最新更新