Set the min property of data table column in JS

On form edit we have a data table with a Quantity column of type Number. Users should be allowed to increase and decrease the number of the quantity for each row, but not less than the original value.

How can i set the Min property for each row item to be that of the original value in JS?

i.e for row 1 when the form loads, if the quantity is set to 10, the Min property should be set to 10, and for row 2 when the form loads, if the quantity is set to 20, the Min property should be set to 20. The number of rows will vary on each form item.

Hi @Arran,

Seems like the best solution is to create an array and fill it with Quantity values at startup, then check the Quantity column against it whenever the control updates.

I suggest using something like this:

let minQuantity = [];

// Change to fd.spRendered(), if you use Forms for SharePoint
fd.rendered(() => {
    fd.control('DataTable').value.forEach((item) => minQuantity.push(item.Quantity));
    fd.control('DataTable').$on('change', () => {
        let items = fd.control('DataTable').value;
        for (let i = 0; i < items.length; i++) {
            if (items[i].Quantity < minQuantity[i]) {
                items[i].Quantity = minQuantity[i];

that worked. thank you :slight_smile:

1 Like