0

Good afternoon, I have this data in a jsgrid table, the fact is that when the database returns the date when displaying it on the page it looks like this: / Date (1614232800000) / what I need is to convert it to DD format / MM / YYYY

Reading the official documentation, there is by default a type of date field as such, but it is possible to modify parameters at will, that being the case, how can I convert the date? I read all from this, any idea, thank you.

http://js-grid.com/docs/#custom-field

First of all, Thanks.

var MyDateField = function (config) {
        jsGrid.Field.call(this, config);
    };

    MyDateField.prototype = new jsGrid.Field({

        css: "date-field",            // redefine general property 'css'
        align: "center",              // redefine general property 'align'

        myCustomProperty: "itemTemplate",      // custom property
        itemTemplate: function (value) {
            return new Date(value).toDateString();
        }
    });

    jsGrid.fields.date = MyDateField;


$('#dgrecordsfound').jsGrid({
  width: "100%",
  height: "350px",
  filtering: false,
  inserting: false,
  editing: false,
  sorting: true,
  paging: true,
  autoload:true,
  pageButtonCount: 5,
  noDataContent:"No records!",
  loadIndication: true,
  loadMessage: "Loading, Please wait",

  pagercontainer:null,
  pageIndex: 1,
  pageSize: 6,
  pageButtonCount: 15,
  pagerFormat: "Pages: {first} {prev} {pages} {next} {last}    {pageIndex} de {pageCount}",
  pagePrevText: "Prev",
  pageNextText: "Next",
  pageFirstText: "First",
  pageLastText: "Last",
  pageNavigatorNextText: "...",
  pageNavigatorPrevText: "...",

  controller: {
     loadData: function () {
        return $.ajax({
           type: "GET",
           datatype: "json",
           data: { parname: "@ViewBag.name"  , parlastname: "@ViewBag.lastname"},
           url: "/asoc/getbyname"
        });
     },
  },

  fields: [
     {
        name: "cod",
        title: "Code",
        type: "text",
        width: 30
     },
     {
        name:"firstname",
        title: "firstname",
        type: "text",
        width: 100
     },
     {
        name: "date",
        title: "Date",
        type: "date",
         myCustomProperty: "itemTemplate",
        width: 30
     }
  ],

  rowClick: function (itemselected) {
     var getdata = itemselected.item;
     var fields = Object.keys(getdata);
     var textarray = [];

     $.each(fields, function (idx, value) {
        textarray.push(getdata[value])
     });

     var url = '@Url.Action("index", "request")' + '/id=1?parCod='+ textarray[1];
     window.location.href = url;
    }
});
  • See https://stackoverflow.com/questions/11591854/format-date-to-mm-dd-yyyy-in-javascript – Pavlo Zhukov Mar 23 '21 at 01:54
  • How can I use the date variable that already comes with the database date so that it can be converted by that function? – Jimmy Grijalva Mar 23 '21 at 02:02
  • There are a lot of examples. If it's not enough, you can look into the linked question inside. Try to implement the convert function yourself: this is how you become a better programmer. – Pavlo Zhukov Mar 23 '21 at 10:59
  • do the conversion myself when I don't know how to do it after reading all the documentation and having done all the code and since it doesn't work, that's why I ask in the forum, what a great idea as it didn't occur to me before, thanks! – Jimmy Grijalva Mar 23 '21 at 17:17

0 Answers0