tabalinas / jsgrid

Lightweight Grid jQuery Plugin
http://js-grid.com
MIT License
1.53k stars 353 forks source link

Need help datetime-local #1418

Closed quidlab closed 1 year ago

quidlab commented 1 year ago

Sorry to post in issues though it is not an issue with jsgrid. Could not find any forum. I am trying to add custom field with datetime-local but having some issues. Everything works fine but value returned by editValue is always current date and time. my code is as below only edit section:


     $(function() {    
     var FoQusDateTimeField = function (config) {
        jsGrid.Field.call(this, config);
    };
    FoQusDateTimeField.prototype = new jsGrid.Field({
        sorter: function (date1, date2) {
            return new Date(date1) - new Date(date2);
        },

        itemTemplate: function (value) {
            if (value === null) {
                return '';
            } else {
                return value;
        //  dates are alrready recived in YYYYMMDDThhmm format      
            }
        },

        editTemplate: function (value) {
            formatedvalue=moment(value).format("YYYY-MM-DDThh:mm");
            this._editPicker = $('<input type="datetime-local" value=' + formatedvalue+'>');
            return this._editPicker;
        },

               editValue: function () {

            var editValue= moment(this._editPicker.value).format("YYYY-MM-DDThh:mm:ss");
            console.log(editValue); // always returns current date and time
            if (typeof editValue !== 'undefined' && editValue !== null) {
                return editValue;
            } else {
                return null;
            }
        }
    });

    jsGrid.fields.FoQusDateTimeField = FoQusDateTimeField;
```javascript
quidlab commented 1 year ago

Fount it :


var editValue= moment(this._editPicker.value).format("YYYY-MM-DDThh:mm:ss");
should be
var editValue= moment(this._editPicker.val()).format("YYYY-MM-DDThh:mm:ss");