Comments (6)
How do you create the datable? Do you use an existing table or JSON array (or something else)?
If the data inside the datatable are of Date
type (not string), then setting using the sort
option should be sufficient.
from datatable.
I used an existing table, created dynamically with php.
I have tried with format 'Y/m/d', works and it orders. But I need show in format 'd/m/Y'.
Thanks.
from datatable.
You can try to use the dataTypes
options:
$('#my-table').datatable({
dataTypes: [true, true, 'date', true, ..., true]
});
You need to fill dataTypes
with true
for all other columns. Using 'date'
, the plugin will try to convert your string to:
new Date(/* initial string */);
If the default converter does not work, you can use a custom one:
function customDate(s) {
// Here you can do whatever you want to convert your string to a date
var dmy = s.split('/');
return new Date(dmy[2], dmy[1], dmy[0]);
}
$('#my-table').datatable({
dataTypes: [true, true, customDate, true, ..., true]
});
from datatable.
Works perfectly, but now it shows me the date in long format
And if I try to change it with the .toLocaleDateString ("es-ES") function
function customDate(s) {
// Here you can do whatever you want to convert your string to a date
var dmy = s.split('/');
var options = { year: "numeric", month: "2-digit", day: "2-digit", hour12:"false"};
return new Date(dmy[2], dmy[1], dmy[0]).toLocaleString('es-ES', options);
}
With the dataTypes: [true, true, 'date'...... Exactly the same happens, show the format long.
from datatable.
You want to internally store date as Date
and then process the output, so you need to use the lineFormat
option:
function customDate(s) {
// Here you can do whatever you want to convert your string to a date
var dmy = s.split('/');
return new Date(dmy[2], dmy[1], dmy[0]);
}
$('#my-table').datatable({
dataTypes: [true, true, customDate, true, ..., true],
lineFormat: function(id, data) {
var res = $('tr');
for (var key in data) {
if (data.hasOwnProperty(key)) {
var value = data[key];
if (value instanceof Date) {
value = toLocaleString('es-ES');
}
res.append('<td>' + value + '</td>');
}
}
}
});
from datatable.
ok, thanks!!!! Now works perfectly.
Thanks so much!!, regards.
from datatable.
Related Issues (20)
- IE 11: Pagination and filter not working correctly HOT 2
- Inject data to table row HOT 4
- Nullpointer Exception table with filter and no data
- Not working on my project :( HOT 6
- CSS not work HOT 4
- Extract filtered records HOT 11
- Filter outside the table HOT 2
- No idea how to make filter outside table HOT 1
- Get number of a table row. HOT 6
- Update table data HOT 19
- Process Ajax Data Before Displaying on Table! HOT 3
- Using Filter/Sort with hidden child rows HOT 3
- Question: How to search/filter multiple columns with one search field HOT 2
- Was cleared all attributes from td. HOT 1
- Click in a row event HOT 3
- Filter by date mm/dd/yyyy HOT 1
- Ajax Doesn't Work HOT 4
- filter is not function after apply addRows HOT 2
- Table reload method HOT 2
- how can i implement for rowspan ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datatable.