I have read some posts to populate the datatable column dropdown selection from a sharepoint list and this is working. I then read about populating a second column in the datatable from static data based on first column selection, but I need to go one step further and when the first column is selected, I want the second column to be automatically populated with the corresponding value in the sharepoint list mentioned above.
I have so far:
//Change RateNames to list from sharepoint
var dt = fd.control('DataTable1');
dt.$on('edit', function(e) {
if (e.column.field === 'RateName') {
//pass widget + current Category value
populateCategories(e.widget, e.model.RateName);
}
})
function populateCategories(widget, value) {
//will show as loading
widget._showBusy();
sp.web.lists.getByTitle('CostRates').items
.select('ID','RateNameUser')
.get()
.then(function(items) {
//set options
widget.setDataSource({
data: items.map(function(i) { return i.RateNameUser })
});
//set value if one was select
widget.value(value);
//hide loading state
widget._hideBusy();
});
}
Then from the help guides I can autopopulate from a static source:
let merch = {};
//use bracket notation to accurately copy dropdown values
merch['D&M Labour - Consultancy 2025'] = 83.18;
merch['D&M Labour - Manufacturing 2025'] = 91.22;
merch['Aero Labour - Technical 2025'] = 100.43
//get a column by its name
var rateColumn = dt.columns.find(c => c.field === 'Rate');
//make column read-only
rateColumn.editable = () => false;
dt.$on('change', value => {
if (value) {
for (let i = 0; i < value.length; i++) {
// populate UnitPrice column
value[i].set('Rate', merch[value[i].RateName] || 0);
> }
}
});
I have tried combinations but am out of my depth here, how do I autopopulate Rate from the CostRates sharepoint list?