date format
date format
suser
Posts: 68Questions: 18Answers: 0
I populate data in jquery like this
```
$("#example").empty()
if (re.length > 0) {
$("#example").append
("<thead><tr><th>StartDate</th><th>EndDate</th></tr></thead>");
for (var i = 0; i < re.length; i++) {
if (re[i] !== null) {
$("#example").append("<tbody><tr><td>" +
re[i][0] + "</td><td>" +
re[i][1] + "</td></tr></tbody>");
}
}
} var myTable;
debugger;
myTable = $('#example').DataTable({
"sPaginationType": "full_numbers",
data: result.d,
//columns: columnDefs,
dom: 'Bfrtip',
"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [3] }], // Needs button container
select: 'single',
responsive: true,
altEditor: true, // Enable altEditor
buttons: [{
text: 'Add',
name: 'add' // do not change name
},
{
extend: 'selected', // Bind to Selected row
text: 'Edit',
name: 'edit' // do not change name
},
{
extend: 'selected', // Bind to Selected row
text: 'Delete',
name: 'delete' // do not change name
}]
});
and this show result like this
StartDate EndDate
/Date(1391194800000)/ /Date(1393613999000)/
```
but in my table column date is correctly formatted..
how i display correct date format do this
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You have two options - use a renderer to convert from the .NET date string to something readable, or modifier your server-side code to output the date in a readable format.
Allan
output is readable format but this display in wrong format
how i use this renderer
ok i do this first i save
sdate= re[i][2];
then i call this like this
but this not works
I'm not sure why you are splitting on a dash?
Date(1391194800000)
doesn't have a dash in it.You'd need to write a function to convert the .NET date string to a readable format. I believe it is in milliseconds from 1st Jan 1900 - but you might want to check in the Microsoft documentation.
Allan
but in .net static method date format is like
2014-02-01 00:00:00.000 start date
2014-02-28 23:59:59.000 end date"
in .net date format is correct problem occur in jquery
You stated above your date is being returned from the server such as
Date(1391194800000)
. If that is what the client-side is seeing, then it is that format that it would need to convert.@allan i mentioned in 2nd last comment that
"but in .net static method date format is like
2014-02-01 00:00:00.000 start date
2014-02-28 23:59:59.000 end date"
means from server side data is correctly formatted but when i try to display this data in datatable data format is like this Date(1391194800000)
check this
and data in store procedure is like this
Yes, that's because your database viewer is correctly interpreting the DateTime and showing it as a formatting string.
Have a look at the JSON data being returned from the server (see this tech note if you don't know how to do that). You will see that the
Date(...)
format is what DataTables is being given by the server. As I stated before, you need to either:Allan
ok means in there is problem is JSON string
@allan ok i solve this but why there is so many empty rows on the starting
Without a link to a test case showing the issue, I can only guess it is because that data that you are having it display contains empty rows. I'd need a test case to know for sure.
Allan
ok check this
https://jsfiddle.net/wtnwgz09/7/
in this dropdown ie.. 10 rows, 20 rows etc is not working and also when i search data is not searching .
You have created 400 opening and closing TBODY tags and you didn't close the TABLE tag.
Change your code to make it a working datatable :
like this?
https://jsfiddle.net/wtnwgz09/8/
but why this is mentioned "No data available in table"
and also show rows dropdown still not working
@allan @F12Magic
"No data available in table" means (in this case) that your table isn't correctly build and that datatables can't be correctly apllied to it.
The rows dropdown works, but can't be displayed because you use "scrollY": 100,
If you remove that, you'll see it works.
Here is a corrected fiddle: https://jsfiddle.net/wtnwgz09/10/
Please use that for future reference.
hey Thanku for this
@F12Magic
but when i try in my code like this as same as in your js fiddle
and i add these links
but this show error on console
Uncaught TypeError: Cannot read property 'parentNode' of null
As far as I can see from your code, you have 3 columns. But you target column 4 in "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [3] }], because arrays are 0 based.
Change that to "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [2] }],
Also I think you're initializing the datatable twice. Remove the line with: var mast_table = $('#master_table').DataTable();
@F12Magic yes i do that
when i do this
then when i open page then this show no data avaible in table so i recode like this
so when i do this then search bar not working
check attach animated gif
or
check this link
http://i.imgur.com/aNb1EIa.gif
My guess is that you have multiple
tbody
elements. Without a link to a test case showing the issue it is impossible to say though.Allan
as this is the test case
this is the test case which i tried but in this perfectly fine but this is the hard coded data
https://jsfiddle.net/wtnwgz09/10/
where as same i did that in my code but not work s
@allan
I'd need a test case showing it not working to be able to help. A test case showing it working doesn't really give me much to debug!
Allan
check this
https://jsfiddle.net/wtnwgz09/12/
@allan
My guess was exactly correct. You are adding a
tbody
every single time in thefor
loop.Indeed again a wrong table structure made by your jquery. You seem to make the same mistake over and over. Anyway, here's a corrected FIDDLE
yes i am done with this
Thanku for help
@F12Magic @allan