Why kendo Ui -grid date is not sorting properly? - kendo-ui

value is ReinsDepositAmount
**
output
**
I have recently stocked with one of the application date sorting in the kendo UI grid.
In kendo grid, the column name is defined like this
Incoming value to ReinsDepositDate - Month,date,year format. 08-23-1991
Field name is ReinsDepositDate:
{
field: "ReinsDepositDate", type: "date", title: "Due Date",format: "{0:M/d/yyyy}", width: 100, filterable: {
cell: {
operator: "contains"
}
}
},
When Sorting the date, its sorting based on first values
1/12/1994
23/1/2015
13/1/1992
means while ascending I am getting
1/12/1994
13/1/1992
23/1/2015
So I have put the schema model
still, I am getting the same result.
schema: {
model: {
fields: {
ReinsDepositDate: { type: "date",format: "{0:dd/MM/yyyy}"}
}
}
},
I have seen lots of fiddle demos nothing works here why:
Refrences:
http://fiddle.jshell.net/NqrDS/light/
Kendo grid date column not formatting
Flow of Design:
Flow of design is by using angular Http service get the value from DB through API and assign the response to datasource in the kendo grid. when I doing a demo with JSON files, its working fine. But the same thing applies it here means not working. so I went to custom javascript to sort. columns:[$scope.grdPrmiumDepositCol, –
Custom javascript in kendo sortable attribute will do the trick.
working fine do this part.
{ field: "ReinsDepositDate", format: "{0:MM/dd/yyyy}",type:"date", sortable:{ compare: function (a, b) {
var c = new Date(a.ReinsDepositDate);
var d = new Date(b.ReinsDepositDate);
return c - d;
}`
}}],
My Question is why I do that because kendo is given the date format and when I tried the sample demo with transport read with JSON file working fine with kendo format. Still in confusion.

Based on the provided information, it is unclear if sorting is performed on the client, or on the server.
If sorting is done on the client by the Kendo UI DataSource, then the date values should be provided in the correct format, so that they are parsed to JavaScript Date objects by Kendo UI. There are multiple different formats that can be parsed, but dd-MM-yyyy is not one of them.
Here is an example, which demonstrates the above. You will notice the empty row, where the date has not been parsed.
http://dojo.telerik.com/UcEXO/2
Generally, it is recommended to serialize dates using commonly accepted standards:
https://stackoverflow.com/a/15952652/3086237
If sorting is performed on the server, then Kendo UI is unrelated to the problem and you should debug the server-side implementation.

You can try parsing the date from response.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.parse
schema: {
parse: function(response) {
for (var i = 0; i < response.length; i++) {
response[i].ReinsDepositDate = kendo.parseDate(response[i].ReinsDepositDate, "dd/MM/yyyy");
}
return response;
}
}
Hope this helps.

Related

How to set filter on OpenUI5 table column so that it triggers filtering

I have a sap.ui.table.Table bound to an OData.V4 data source. The filterProperty of each column is correctly set.
With this I can successfully set a filter value, either using the cell rightClick or in the column header popup menu. This behaves exactly as expected in that an updated request is sent to the OData source with the correct filtering.
For reasons based on the overall requirements, I wish to save the filter settings which I do to a JSON model:
var oTable = this.byId("table");
var aColumns = oTable.getColumns();
var columns={};
var settings=[];
var filtered=false;
for (var i = 0; i < aColumns.length; i++) {
if(aColumns[i].getFilterValue()) filtered=true;
settings.push({
"index": i,
"id":aColumns[i].getId(),
"sorted": aColumns[i].getSorted(),
"sortOrder": aColumns[i].getSortOrder(),
"filterValue": aColumns[i].getFilterValue(),
"filtered": aColumns[i].getFiltered(),
"visible": aColumns[i].getVisible()
});
}
columns.settings = settings;
columns.filtered = filtered;
A user can then try and recall a set of filter and sort settings, the code for which is shown below, where thisCrumb contains the saved settings:
var oTable = this.byId("table");
var columns = thisCrumb.columns;
if(columns){
if(columns.search )this.byId("searchField").setValue(columns.search);
for(var columnIndex in columns.settings){
var column = oTable.getColumns()[columns.settings[columnIndex].index ]
column.setFilterValue(columns.settings[columnIndex].filterValue );
oTable.filter(column, columns.settings[columnIndex].filterValue);
column.setFiltered(columns.settings[columnIndex].filtered );
column.setSortOrder(columns.settings[columnIndex].sortOrder );
column.setSorted(columns.settings[columnIndex].sorted );
column.setVisible(columns.settings[columnIndex].visible);
}
}else{
this.clearAllFilters();
this.clearAllSorts();
}
Although the values show up on the table, for example the filter icon is set on the column header, and the filter value is also set, the OData query to refresh the data does not include the filter values.
The API documentation suggest that the sap.ui.table.Table.filter method should be called for each column, which I have done (as above) but with no success:
oTable.filter(column, columns.settings[columnIndex].filterValue);
If I interactively use the column header contextmenu and 'touch' the filter value, the table does get refreshed including the corresponding filter.
I would like to be able to recover a saved set of filter and/or sort values, apply them to each column, and then refresh the Table to show the filtered set
OK so I eventually resolved this problem. In the examples above I had assumed that I was manipulating the filter that would be applied to the model endpoint. This is not the case. All I was doing in this example code was manipulating the filters displayed on the Table, in the drop down box etc.
To save and reapply the filters I had to access the row binding on the table:
columns.aFilters = oTable.getBinding("rows").aFilters;
However I still had problems because there are two filters: control and application binding. The application filters are as follows:
columns.aApplicationFilters = oTable.getBinding("rows").aApplicationFilters;
Then when I select a different set of filters, they need to be bound to the rows aggregation as follows:
oTable.bindAggregation("rows", {
path: sObjectPath,
parameters: expand,
filters:filters,
sorter:sorter
});
where filters is either
columns.aFilters or columns.aApplicationFilters

Getting Audit Record Details from Dynamics 365 to Power BI

I have been able to pull down an audit table from Dynamics 365 and load it into Power BI by selecting Get Data, choosing the odata option and using url/api/data/v9.1/audits. I see the column RetrieveAuditDetails, but I don't understand why all the values say Function. Is there a way to extend this to show the old value/new value in the same way you can change, for example, UserIDs to be extended to the full name?
When it comes to audit data, OData/Web API REST endpoint is not so friendly in PowerBI due to the reason that the audit data is stored as delimited values in database. Refer my answer in this SO thread.
If it's a javascript or .net application you can do iterative call using RetrieveAuditDetails function to fetch full details after getting full list using https://crmdev.crm.dynamics.com/api/data/v9.1/audits. This is why you are seeing as Function in there.
For example:
var parameters = {};
var entity = {};
entity.id = "5701259e-59b8-e911-bcd0-00155d0d4a79";
entity.entityType = "audit";
parameters.entity = entity;
var retrieveAuditDetailsRequest = {
entity: parameters.entity,
getMetadata: function() {
return {
boundParameter: "entity",
parameterTypes: {
"entity": {
"typeName": "mscrm.audit",
"structuralProperty": 5
}
},
operationType: 1,
operationName: "RetrieveAuditDetails"
};
}
};
Xrm.WebApi.online.execute(retrieveAuditDetailsRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
Update:
On further analysis - there is no big difference between the output schema from the above RetrieveAuditDetails query targeting single auditid or the below filtered audits query targeting single recordid.
https://crmdev.crm.dynamics.com/api/data/v9.1/audits?$filter=_objectid_value eq 449d2fd8-58b8-e911-a839-000d3a315cfc
The fact is either web api or fetchxml, the resultset cannot fetch the important column changedata which contains the changed field values - due to the restriction: Retrieve can only return columns that are valid for read. Column : changedata. Entity : audit
I get this in FetchXML builder:
There is another approach but not PowerBI compatible anyway, using RetrieveRecordChangeHistory to target the recordid to get all the audit collections with old & new values. Example below:
https://crmdev.crm.dynamics.com/api/data/v9.0/RetrieveRecordChangeHistory(Target=#Target)?#Target={%22accountid%22:%22449d2fd8-58b8-e911-a839-000d3a315cfc%22,%22#odata.type%22:%22Microsoft.Dynamics.CRM.account%22}

Formating date values for display in Can.js

All my dates come formatted as ISO 8601 from the backend, eg 2014-01-01T12:45:30Z. Across the application, I want to display them in different formats...
shorthand in tables, eg Jan 1
longer, more explicit format on a detailed view, eg Monday, January 1st.
Solution I made a helper where I can pass in the format. Easy enough.
can.mustache.registerHelper('formatDate', function(date, format) {
return date() ? moment(date()).format(format) : '-';
});
Problem Now I'm implementing the bootstrap datepicker, how can I capture these requirements...
the date in my model is formatted as ISO
bind to input with can-value in template
display format MM/DD/YY for users and datepicker
Bonus points if I don't need to make a compute for every single date value in my models, as they're quite large and with many dates.
Unfortunately there isn't a nice API for this(yet). However, you can achieve custom formats in a view while keeping your model properties pristine with the below code.
can.view.attr('can-somecustom-value', function(el, data) {
var attr = el.getAttribute('can-somecustom-value'),
value = data.scope.computeData(attr, {
args: []
}).compute;
new FormattedValue(el, {
value: value
//value is the only one we really care about, but
//you could specify other arbitrary options here
//such as "format: 'MM/DD/YYYY' to be used in your __format methods below"
});
});
var FormattedValue = can.Control.extend({
init: function () {
this.set();
},
__format: function() {
// return formatted version of this.options.value;
},
__deformat: function() {
// return this.element[0].value sans format(keeps your model pristine);
},
'{value} change': 'set',
set: function () {
if (!this.element) {
return;
}
var self = this;
setTimeout(function() {
self.element[0].value = self.__format();
});
},
'change': function () {
if (!this.element) {
return;
}
this.options.value(this.__deformat());
}
});
This will allow you to do the following:
<input can-somecustome-value="myDateProp"/>
where "myDateProp" is an attribute on some can.Map/can.Model/etc.
This will result in the input displaying a custom string format, while someModel.attr('myDateProp') will still return the ISO format(which in turn means the ISO format will also be saved to the server).
There is some internal discussion regarding adding filters/parsers to allow control over formats specific only to view rendering.

Kendo AutoComplete

I want to use kendo AutoComplete in a kendoGrid for inline editing. When user inputs anything I'd use it to call a RESTful web service to return a list of products with names that start with the input value.
My questions are:
My web service expects a request looks like http://localhost/myService/appl where "appl" is the value that user enters and the prefix. However, kendo seems to always format the request something like http://localhost/myService?product=appl. How do I change the format?
How do I get the value that user has input in the grid (the AutoComplete textbox) so I can pass it in the request URL?
Define in the DataSource of your autocomplete an url function.
In that function, you can get typed value as:
var val = op.filter.filters[0].value;
and then return the url with the composed value.
Then it is something like:
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: function (op) {
var val = op.filter.filters[0].value;
return "/myService/" + val;
}
}
}
})

BreezeJS does not automatically parse numbers saved as strings with KnockoutJS bindings

I queried my database using Breezejs using the following code:
viewModel = {
products = ko.observableArray([])
};
var manager = new entityModel.EntityManager('/api/Products');
manager.executeQuery(query)
.then(function (data) {
viewModel.products.removeAll();
viewModel.products(data.results);
});
However the products rows contain numeric properties like Quantity which are wired to my page using the data-bind property. On saving the model through manager.saveChanges() I get a validation error. This is because KnockoutJS saves the edited numbers as strings.
What's the recommended way to get around this issue?
As of breeze v 0.80.2, this capability is now supported. ( along with the capability to customize type coercion)
One option is to create a CustomBinding.
I use this for decimals:
ko.bindingHandlers.decimal = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
$(element).blur(function () {
var value = valueAccessor();
var valor = Globalize.parseFloat($(element).val());
if (ko.isWriteableObservable(value)) {
value(valor);
ko.bindingHandlers.decimal.update(element, valueAccessor);
}
});
},
update: function (element, valueAccessor, allBindingsAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).val(Globalize.format(value, "n2"));
}
};
It's a good question.
Currently, breeze does not attempt type coercion, but...
We have discussed having Breeze automatically attempt to coerce any values used within a set operation to the datatype of the property being set ( as defined in breeze metadata). This would occur across all binding libraries, (i.e angular, backbone etc) as well as knockout.
Please feel free to add this to the breeze User Voice. We take these submissions very seriously.

Resources