jQWidgets Forums

jQuery UI Widgets Forums ASP .NET MVC MVC Json result Datetime format issue in grid

This topic contains 3 replies, has 3 voices, and was last updated by  Hristo 7 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • saurabhshah
    Participant

    Hi,
    I am trying to use jqxgrid with date in one of the column.
    Here is my ode for it.

    Here is a column which I added in my html.
    { text: ‘Expiration’, datafield: ‘ExpirationDate’, width: 300, cellsformat: ‘d’ },

    I am returning json result but I see an output like this.
    /Date(1514700000000)/
    how can i keep my original date to grid?

    Thanks,


    Hristo
    Participant

    Hello saurabhshah,

    If you want to have a simple number you could set this datafield from type number.
    Please, take a look at this example:

    var data = [
                    { name: 'Ian', dateString: 1514700000000 },
                    { name: 'Cheryl', dateString: 1614700000000 },
                    { name: 'Petra', dateString: 1714700000000 }
                ];
                var source = {
                    localdata: data,
                    datafields: [
                        {
                            name: 'firstname',
                            map: 'name',
                            type: 'string'
                        }, {
                            name: 'date',
                            type: 'date'
                        },
                        {
                            name: 'dateString',
                            type: 'number'
                        }
                    ],
                    datatype: "array"
                };
                var adapter = new $.jqx.dataAdapter(source, {
                    beforeLoadComplete: (records) => {
                        for (var i = 0; i < records.length; i += 1) {
                            var rec = records[i];
                            console.log(rec.dateString);
                            rec.date = new Date(rec.dateString);
                        }
    
                        return records;
                    }
                });
    
                $("#jqxgrid").jqxGrid({
                    width: 400,
                    autoheight: true,
                    theme: 'energyblue',
                    source: adapter,
                    filterable: true,
                    columns: [
                        {
                            text: 'First Name',
                            datafield: 'firstname',
                            columngroup: 'Name',
                            width: '30%'
                        }, {
                            text: 'Order Date',
                            datafield: 'date',
                            cellsformat: 'dd-MM-yyyy',
                            align: 'right',
                            cellsalign: 'center'
                        }, {
                            text: 'Simple Text',
                            datafield: 'dateString',
                        }
                    ]
                });

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com


    Admir Hodžić
    Participant

    Hristo
    Participant

    Hello saurabhshah,

    It is about null value set for some dates.
    Could you clarify if it does not help you the example above?

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.