DataTable - Auto-populate Today's Date

Hello, in the past, if selecting a DataTable column type as "Date" it would auto populate with today's date. It doesn't seem to do that now. How do I get Today's date (MM/DD/YYYY) populating when a new record is added to the table?

The code that I've been using for my table is this:

image

Thanks.

Hi @ParAvion,

You can do this as described here:

fd.rendered(() => {
    fd.control('DataTable1').widget.bind('beforeEdit', function(e) {
        var model = e.model;
        if (model.isNew()) {
            model.set('DateColumn', new Date());
        }
    });
});

@IliaLazarevskii thank you. Can you show me how to incorporate that into my existing code?

fd.spRendered(function() {
fd.control('DataTable2').$on('change',
function(e) {
var username = _spPageContextInfo.userDisplayName;
fd.control('DataTable2').value[0].Column3 = username;
});
});

Hi @ParAvion,

Try this:

fd.spRendered(function() {
    fd.control('DataTable2').$on('change', function(e) {
        var username = _spPageContextInfo.userDisplayName;
        fd.control('DataTable2').value[0].Column3 = username;
    });

    fd.control('DataTable2').widget.bind('beforeEdit', function(e) {
        var model = e.model;
        if (model.isNew()) {
            model.set('DateColumn', new Date());
        }
    });
});
1 Like