Author Topic: Insert date with the format "dd-mm-yyyy"  (Read 5025 times)

altyra

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 12
    • View Profile
Insert date with the format "dd-mm-yyyy"
« on: November 22, 2019, 10:22:26 pm »
Hi,

I have an issue, i need to introduce the date in my paramquery with the format "dd-mm-yyyy", but the only solutions i am finding are to change the date from "mm-dd-yyyy" to "dd-mm-yyyy" and everytime i try to put "dd-mm-yyyy" it clears my text, is there anyway that i can introduce the format that i want from the start?

Thamk you for your time

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #1 on: November 25, 2019, 09:42:21 am »
Initially the date data types should be in "mm/dd/yy" or "yy-mm-dd" format in json data.

https://paramquery.com/pro/api#option-column-dataType

If your dates are in "dd-mm-yy" format initially, you can convert them into "mm/dd/yy" format in dataModel.getData callback with help of jQueryUI datepicker methods $.datepicker.parseDate( format, value) and $.datepicker.formatDate(format, val)

Then set column.format = "dd-mm-yy"

Rest is same as done for "OrderDate" column in this demo: https://paramquery.com/pro/demos/editing_custom

altyra

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #2 on: November 26, 2019, 07:44:20 pm »
But the main problem is that i cant even introduce the date with the format "dd-mm-yyyy" it automatically clears out my text, in my context i need to copy/past a larger portion of data into my paramquery.

Thank you for your time

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #3 on: November 27, 2019, 06:05:28 pm »
Also in case of copy / paste the dates should be in "mm/dd/yy" or "yy-mm-dd" format.

If pasted dates are in any other format, then they have to be converted to above format in beforePaste event:

https://paramquery.com/pro/api#event-beforePaste

Please let me know if you need further assistance on this.

altyra

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #4 on: November 28, 2019, 03:06:09 pm »
Now my code looks like this and works perfectly

Code: [Select]
beforePaste: function (evt, ui) {
                        //sanitize pasted data.
                        var CM = this.getColModel(),
                            rows = ui.rows,
                            area = ui.areas[0],
                            c1 = area.c1;
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            for (var j = 0; j < row.length; j++) {
                                var column = CM[j + c1],
                                    dt = column.dataType;
                                if (dt == "date") {
                                    var $m = row[j].match(/^(\d+)-(\d+)-(\d+)$/);
                                    var $new = $m[2] + "-" + $m[1] + "-" + $m[3];
                                    row[j] = $new;
                                }
                            }
                        }
                    },

But i have one last question, is there a way to do the same but with the cell click and cell submit?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #5 on: November 28, 2019, 08:38:55 pm »
Quote
is there a way to do the same but with the cell click and cell submit?

cell click doesn't change the data in grid.
can you please elaborate it a little bit?

altyra

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #6 on: November 28, 2019, 08:53:06 pm »
When i click to edit the cell it displays the date as "mm-dd-yy" and i want to change it to the format "dd-mm-yy", and when i submit the changes to the cell transform it back in to the format "mm-dd-yy" so that it can be recognized by the grid as a valid date.

I am thinking of using the functions beforeFillHandle (to display) and cellBeforeSave (to save) to achieve these results, but i am having trouble applying them, could you send me an example or should i use other functions?

Thak you for your time once again.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Insert date with the format "dd-mm-yyyy"
« Reply #7 on: November 28, 2019, 09:11:56 pm »
That's quite simple, you have to define column format as "dd-mm-yy" and define dateEditor as in this demo:

https://paramquery.com/pro/demos/editing_custom

jsfiddle: https://jsfiddle.net/nby2arfk/1/