Manipulating the add row function in a dialog box

Hi, I’ve created a dialog box “insertDialog” with a table “Questions” inside it, having a field “qno”. I want to make it so that, whenever a new row is added, the qno gets autofilled with the idx of the new row, or idx of previous + 1. I’ve tried adding a default attribute to the field, and changing the get_data function. None of them worked out.

This is the simplified code I’ve written till now.

let insertDialog = new frappe.ui.Dialog({
		title: 'Please enter the required details',
		fields: [
                {
                    label: `Questions`,
                    fieldname: `questions`,
                    fieldtype: 'Table',
                    data: data,
                    get_data: () => {
                         return data;
                    },
                    fields: [
                        {
                            label: `Q. No.`,
                            fieldname: 'qno',
                            fieldtype: 'Int',
                            in_list_view: 1,

                        }
                  ]
            }

Another thing I tried is defining it outside the dialog box definition

insertDialog.fields_dict['questions'].grid.get_field('qno').default = data.length + 1;

However, it still didn’t work.