In an attempt to create a list sortable by date, I created the following datasource:
sort: { field: 'dateTime', dir: 'asc' },
schema: {
model: {
id: 'Id',
fields: {
dateTime: {
field: 'DateTime',
type: 'Date',
parse: function (value) {
return kendo.toString(kendo.parseDate(value), 'MM/dd/yyyy hh:mm tt');
}
},
stuff: 'Stuff'
}
}
}
After filling it with data, I noticed that the rows in the bound list were sorting alphabetically like:
01/02/2015 08:22 PM
12/12/2014 09:00 PM
12/18/2014 08:22 PM
How can I get these dates to sort in ascending chronological order?
I imagine this occurred because the value was converted to a string in the parse function so it was no longer sorting like a date so I removed the parsing code from the field:
sort: { field: 'dateTime', dir: 'asc' },
schema: {
model: {
id: 'Id',
fields: {
dateTime: {
field: 'DateTime',
type: 'Date'
},
stuff: 'Stuff'
}
}
}
This reverted the dates shown in the listview to the default format: (Fri Dec 12 2014 21:00:00 GMT-0500 (Eastern Standard Time)), but it now sorted correctly. The final piece of the puzzle is to instead bind my element to a calculated property that parses the date instead of the dateTime field like so:
HTML
<!-- The element: -->
<td data-bind="html: myDate" style="width: auto;"></td>
JavaScript
// And in the observable:
myDate: function(e) {
return kendo.toString(kendo.parseDate(e.dateTime), 'MM/dd/yyyy hh:mm tt');
}
This worked like a charm and I got this:
12/12/2014 09:00 PM
12/18/2014 08:22 PM
01/02/2015 08:22 PM
Optionally, if you have a DateTimePicker bound to your dateTime property your myDate calculated property will not update when you change it. I solved this by listening for the change and triggering the change event manually:
viewModel.bind('change', function (e) {
if (e.field == 'selectedEvent.dateTime') // or whatever your property comes out as
viewModel.trigger('change', { field: 'myDate' });
});
Related
here is my KendoGrid :
$scope.gridEltCompoOptions = {
dataSource: {
transport: {
...
},
schema: {
model: {
id: 'IdElement',
fields: {
GroupeActes: { defaultValue: { IdGroupeActes: null, Libelle: ' ' } }
}
}
}
},
sortable: true,
resizable: true,
filterable: {
mode: 'row'
},
columns: [{
field: 'GroupeActes',
title: "Groupe d'actes",
template: function (dataItem) {
return kendo.toString(dataItem.GroupeActes.Libelle);
}
}, ]
I want to filter my field 'GroupeActes' on the property Libelle (GroupeActes is an object), but actually the filter take the entire object.
When i try to filter, i have a Js Error
Uncaught TypeError: (d.GroupeActes || "").toLowerCase is not a function
The problem is clear, the filter is taking the entiere object, not the property Libelle.
i passed the last 4 hours to try all the solutions i found on google but nothing is working
my object GroupeActes is like this :
var GroupeActes = {
GroupeActes : {
Libelle : ""
}
}
there is two groupeActes level
I saw a post in 2015 of an Admin, saying this kind of filter isn't possible,
but i saw also this kind of solution :
https://docs.telerik.com/kendo-ui/knowledge-base/grid-filter-column-with-dropdownlist
(if(e.field == "Category" && e.filter !== null){) in the example
i tried to do something like : if field == "groupeActes" => so i want to filter on Libelle properties,
but i didn't success
Can someone help me please ?
thank you so much
Have you looked at this article: https://docs.telerik.com/kendo-ui/knowledge-base/enable-operations-for-object-column
I believe you can accomplish what you want by setting the column field to "GroupeActes.Libelle" instead of using a column template:
columns: [
{
field: 'GroupeActes.Libelle',
title: "Groupe d'actes",
},
],
See this DEMO:
Hi I'm new to these two frameworks and I need your help !
So I'm using Rest Django for backend and Angular for Frontent , I'm also using Angular material for the DatePicker , although I changed the format of the date to YYYY-MM-DD to the DatePicker I still receive an error message "Date has wrong format. Use one of these formats instead: YYYY-MM-DD." by the server when sending the api !
to change the date format in Angular I used this code into app.module
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '#angular/material/core';
import { MomentDateModule, MomentDateAdapter } from '#angular/material-moment-adapter';
export const DateFormats = {
parse: {
dateInput: ['YYYY-MM-DD']
},
display: {
dateInput: 'YYYY-MM-DD',
monthYearLabel: 'MM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MM YYYY',
},
};
providers: [
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{ provide: MAT_DATE_FORMATS, useValue: DateFormats }
],
After console.log('date',this.date) to see the date object entered by the datepicker I received
date
{…}
_d: Date Tue Aug 18 2020 00:00:00 GMT+0100 (UTC+01:00)
_i: Object { year: 2020, month: 7, date: 18 }
_isAMomentObject: true
_isUTC: false
_isValid: true
_locale: Object { _calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", … }
_pf: Object { empty: false, overflow: -1, charsLeftOver: 0, … }
<prototype>: Object { add: createAdder(val, period), calendar: calendar$1(time, formats), clone: clone(), … }
Do you know how can I solve the problem please ?
u should create a method to trim ur date removing the timezone & other inform then call the method in ur date input field
something like this
yourDateApp.component.ts file
trimDate(myDate){
let strDate = JSON.stringfy(myDate.value)
let newDate = strDate.substring(1, 11)
//assign the new trimmed date to date value in ur form
yourForm.controls['date_field'].setValue(newDate)
}
yourDateApp.component.html file
//call your function in the html file like this
<input matInput (dateChange)="trimDate($event)">
this will accept the date trim it to a way django will recognize it
I am trying to display data from table in sorted way. I want to display content ordered by creation date. I add sortInfo, but it does not work! I use angular ui-grid. Here is my code
$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{ field: 'name'},
{ field: 'age'},
{ field: 'creationDate', cellFilter : "date:'yyyy-MM-dd'"}
],
sortInfo: {
fields: ['creationDate'],
directions:['desc']
}
};
Is it possible to set sort by default here? And how to do it?
I didn't found in ui-grid docs sortInfo option.
Your gridOptions is not set right. You need to add the sort property to your column definition like below, the priority is what makes it sort by default. Lower priority gets sorted first. Read more here http://ui-grid.info/docs/#/tutorial/102_sorting
$scope.gridOptions = {
enableSorting: true,
columnDefs: [
{
field: 'name',
sort: {
direction: uiGridConstants.DESC,
priority: 1
}
}
}
My kendo grid is showing date like this /Date(691869600000)/ . How do i solve this?
Using this answer I got the Steve code to work for my case. Try this template:
"#= kendo.toString(new Date(parseInt(myField.substr(6))),'MM/dd/yyyy HH:mm tt')#"
'#= kendo.toString(yourDateField,"MM/dd/yyyy HH:MM tt")#'
and make your field type as date.
You need to specify the date as a type in your datasource definition - else it will just be a string:
For example if your field is birthday:
var kendoDS = new kendo.data.DataSource({
schema: {
model: {
fields: {
birthday: { type: "date"}
}
}
});
And when you define the Grid:
kendoGrid({
selectable: whatever values..etc
columns: your-response,
dataSource: kendoDS
});
See this for more info: http://www.kendoui.com/forums/framework/data-source/json-date-handling-changed-in-latest-release.aspx
Use template like the following or like the one in the documentation link.
#= kendo.format("{0:d}",theDateTimeFieldName)#
var offsetMiliseconds = new Date().getTimezoneOffset() * 60000;
#= kendo.toString(new Date( parseInt(JSONDateTime.substr(6)) + offsetMiliseconds),"dd-MMM-yyyy hh:mm tt") #
/Date(1352658600000)/
When Display the date Date is not Display in Proper Format.
How to convert in to proper Format(dd/mm/yyyy)?
All you need to make the conversion is setting date formatter in jqGrid colum model:
$('#gridId').jqGrid({
...
colModel: [
...
{ name: 'Column Name', index: 'Column Index', ..., formatter: "date", formatoptions: { newformat: "m/d/Y"} },
...
],
...
});
For the newformat option jqGrid supports PHP date formatting.
Taken from the accepted answer here - Converting json results to a date
You need to extract the number from the string, and pass it into the Date constructor:
var x = [ {"id":1,"start":"\/Date(1238540400000)\/"}, {"id":2,"start":"\/Date(1238626800000)\/"} ];
var myDate = new Date(x[0].start.match(/\d+/)[0] * 1));
The parts are:
x[0].start - get the string from the JSON
x[0].start.match(/\d+/)[0] - extract the numeric part
x[0].start.match(/\d+/)[0] * 1 - convert it to a numeric type
new Date(x[0].start.match(/\d+/)[0] * 1)) - Create a date object