Dateformat to dd.mm.yyyy editortables
Dateformat to dd.mm.yyyy editortables
tableFan
Posts: 10Questions: 7Answers: 0
Hello,
I've been trying to set the date to dd.mm.yyyy for days but it doesn't work. I tried with moment, but unfortunately it didn't work, can someone help me? This is my code:
public ActionResult EditorTable()
{
//var connString = Configuration.GetConnectionString("DevContext");
string dbConnection = this._configuration.GetSection("ConnectionStrings")[connection];
//DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", Microsoft.Data.SqlClient.SqlClientFactory.Instance);
using (var db = new Database("azure", dbConnection))
{
var response = new Editor(db, "Model")
.Model<Model>()
.Field(new Field("column1"))
.Field(new Field("column2"))
.........
.Field(new Field("columnDATE"))
.TryCatch(false)
.Process(Request)
.Data();
return Json(response);
}
}
var editor;
$(document).ready(function(){
editor = new $.fn.dataTable.Editor ({
ajax: {url: "/Controller/EditorTable" , type: "POST"},
table: "#tbl",
fields: [{
label: "column1",
name: "column1",
type: "select",
options: dropdownColumn1.value
},
..........................
{
label: "datum",
name: "columnDATE",
type: "datetime",
def: function () { return new Date(); }
}
]
});
Answers
Using moment.js this line should give you today's date in the format you require. And yes: This is case sensitive! dd.mm.yyyy will NOT work.
If you want to achieve the same using plain javascript it gets a little complicated. I wouldn't use it. You need to get moment.js going anyway, e.g. for international date sorting and the like using the universal date sorting plug in (or whatever it was called).
https://datatables.net/plug-ins/sorting/datetime-moment