format date columns datatables editor

format date columns datatables editor

marchemarche Posts: 2Questions: 1Answers: 0
edited March 2021 in Free community support

Is it possible for the datatables editor for a date field to pass in the format for the entire row, in stead of defining it on every column?
With one statement that alters all the datetimeformats in the editor row

At this moment we have several datatables with generic columns where we pass in the columndefinitions to a script with JSon. Also the datatables datefields are depending on the locale format of the country (where we use moment.js) for.

At this moment in the json we define the type for the column as 'datetime', but passing in the format in the json where this is generic with moment in place, and here we also have to pass the local format in the moment.format(...) looks like not an option, or is there a possibility.

                data-js-datatable-editor='{
                    "CrudUrl": "/JobTimeRegistration/DatatableEditorSave",
                    "Fields":
                    [
                        {"label": "Projectname", "name": "Projectname", "type": "readonly", "attr": { "disabled":"true" }},
                        {"label": "Jobname", "name": "Jobname", "type": "readonly", "attr": { "disabled":"true" }},
                        {"label": "User", "name": "User", "type": "readonly", "attr": { "disabled":"true" }},
                        {"label": "Category", "name": "Category", "type": "select", "options": [
                                {"value" : "Meeting", "label": "Meeting"},
                                {"value" : "Creative", "label": "Creative"},
                                {"value" : "Layout", "label": "Layout"},
                                {"value" : "Correction", "label": "Correction"},
                                {"value" : "FinalDelivery", "label": "FinalDelivery"}
                            ]},
                        {"label": "Comment", "name": "Comment", "type": "text"},
                        {"label": "Date", "name": "Date", "type": "datetime"},
                        {"label": "Start", "name": "Start", "type": "datetime", "format": "HH:mm"},
                        {"label": "End", "name": "End", "type": "datetime", "format": "HH:mm"},
                        {"label": "Total", "name": "Total", "type": "readonly", "attr": { "disabled":"true" }},
                        {"label": "IsBilled", "name": "IsBilled", "type": "select", "options": [
                                {"value" : "Yes", "label": "Yes"},
                                {"value" : "No", "label": "No"}
                            ]},
                        {"label": "Buttons", "name": "Buttons"}
                    ],
                    "Columns":
                    [
                        { "data": "Projectname" },
                        { "data": "Jobname" },
                        { "data": "User" },
                        { "data": "Category", "isActive": true },
                        { "data": "Comment", "isActive": true },
                        { "data": "Date", "isActive": true },
                        { "data": "Start", "isActive": true },
                        { "data": "End", "isActive": true },
                        { "data": "Total" },
                        { "data": "IsBilled", "isActive": true }
                    ],
                    "SubmitType": "all",
                    "ColumnActiveIndex": 9,
                    "ColumnActiveString": "No"
               }'>

Thanks.

Answers

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin

    datatables editor for a date field to pass in the format for the entire row, in stead of defining it on every column?

    No sorry - each field is configured individually. You could assign a variable and then use that though:

    let format = 'HH:mm';
    

    then:

    format: format
    

    in the field definition object.

    Allan

  • marchemarche Posts: 2Questions: 1Answers: 0
    edited March 2021

    As I mentioned. It is generic that means the format can be 'yyyy/mm/dd' or 'dd/MM/yyyy' or 'dd-mm-yyyy'. But I have to pass it in to the json.
    Or is there a way I can iterate over the columndefs so I can override the original formats?

    Marc

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin

    Oh I see - sorry. I misunderstood.

    Currently no - you need to know the format as you initialise the DataTable. You could make an Ajax request to get that format(s) (and also the data if you wanted to do it in a single request, and then use data rather than ajax).

    Allan

This discussion has been closed.