How to retrieve Project Number from a column in Datatable Plumsail

Hi here,

I created a datatable looking like the following: I want to store all the project numbers in the first column (Project) of the data table into the text field called Project_Num text field. How do I achieve this? And how I can delete the project numbers in the textfield when the project numbers in the datatable are deleted as well? Thanks.

Hello @jyou,

You can use the code below to prepopulate column value for new row. Make sure you are using valid control and field internal names in the code.

fd.spRendered(function() {
    //select the Data Table control to automatically prepopulate new rows
    var dt = fd.control('DataTable1');
    var isNew = false;

    dt.widget.wrapper.find('.k-grid-add').on('click', e => {
        isNew = true;
    });

    dt.widget.bind('edit', function(e) {
        if (isNew) {
            isNew = false;
            e.model.set('Project', fd.field('Project_Num').value);
        }
    });
});

You can find more code examples for working with the DataTable in our documentation here.

@mnikitina

Thank you for the reply. Unfortunately, the code above doesn't work. I tried and I am not getting any values in the "Project Num". Please advise

@jyou,

Please check if there are any errors in the browser console(F12) when you add a new record to the DataTable. Share the screenshot.

@mnikitina

I think you have misunderstood me. I meant to say that i don't enter anything in the "Project_Num" textfield. I only enter in the datatable. When I have multiple project numbers filled out in the datatable, I want to transfer these project numbers from datatable into the "Project_Num" textfield.

if I were to delete project numbers in the datatable, the changes should get reflected too in the "Project_Num" textfield.

Thanks,

@jyou,

Yes, I've misunderstood you. To populate fild value with the DataTable column value you can use this code:

fd.control('DataTable1').$on('change',function(value) {
  
  var names = value.map(function(item) {
    return item['ColumnName'];
  });
  
  fd.field('FieldName').value = names.join('; ');
});

@mnikitina

many thanks. :smiley: :smiley: :smiley:

1 Like