Kendo Grid Date Filter - kendo-grid

I'm trying to use the kendo grid date filter as seen here: http://demos.kendoui.com/web/grid/filter-menu-customization.html
I'm not seeing any good examples on how to do this using Razor syntax.
The only example they show is using javascript:
{
field: "BirthDate",
title: "Birth Date",
format: "{0:MM/dd/yyyy HH:mm tt}",
filterable: {
ui: "datetimepicker"
}
}
I tried to do this on my column, but it didn't work:
cols.Bound(c => c.DateOfServiceString).Title("Assessment Date").Filterable(filterable => filterable.UI("datetimepicker"));

There is an option to view cshtml code in the kendo demo page itself.
Here is the link you need.
http://demos.telerik.com/aspnet-mvc/grid/filter-menu-customization
Also, I believe if the data is coming as DateTime, kendo will automatically convert it to javascript date object. Hope this helps.

I have a feeling i've stumbled across this issue - try adding this JS snippet after your Grid Helper.
<script type="text/javascript">
function datetimepicker(control) {
$(control).kendoDateTimePicker();
}
</script>

I have this working in my code. I have define the column type as date and converted the date string to Date object.
Here is the code that defines the column
column.field= 'c5',
column.title= "Date",
column.type = 'date',
column.template = '#= kendo.toString(c5, "g" ) #';
column.filterable = {
operators: {
date: {
lt: "Lesser than",
gt: "Greater than"
}
}
}
After I fetch the data from the server, I convert it to Date object.
vm.feedbacks = [];
rows.forEach(function (row) {
row.forEach(function (column, index) {
var key = 'c' + index;
feedback[key] = column;
if (gridColumns.gridAllColumns[index].type === 'date') {
feedback[key] = new Date(column);
};
});
vm.feedbacks.push(feedback);
});

Related

It's possible to export only a portion of the values of a datatable column?

I have a datatable with a button to export its data to a pdf file using pdfmake. So far so good until I received the request to add one more value to one of the columns (and this value should not appear in the exported data). The column I'm having this problem has the following composition:
<td>{{client.lot}}<br><p>{{client.lot.total_negotiations}} client(s) negotiating!</p></td>
(Ok, I know this is not the best way to split all cells of the column into two rows)
What I'm trying to do is to export the data only with the "first row" (before the <br> tag). How can I accomplish this? There's any workaround adjusting the table or the pdf?
You can use the exportOptions.format() function provided by DataTables to do this.
For example, assuming we start with the following table data (where there are 2 cells containing data which needs to be formatted):
Then the resulting PDF will look as follows:
The DataTables configuration for this is:
$(document).ready(function() {
$('#example').DataTable( {
"dom": 'B<"clear">lfrtip',
buttons: [{
extend: 'pdf',
text: 'Save as PDF',
exportOptions: {
modifier: {
page: 'current'
},
format: {
body: function ( data, rowIdx, colIdx ) {
if (colIdx == 1) {
var brIdx = data.indexOf("<br>");
if (brIdx >= 0) {
return data.substring(0, brIdx);
} else {
return data;
}
} else {
return data;
}
}
}
}
}]
} );
} );
This uses a function to inspect the contents of each cell. In my case, I ignore any data which is not in column index 1 (the 2nd column in the table).
For each cell of data in this column, I check for the existence of a <br> tag in the data. If one exists, then all data from this tag to the end of the string is discarded.
All other cells in all other columns are passed through to the PDF unchanged.
You may need to adjust this, depending on your specific needs (e.g. if you need to handle multiple columns, maybe to clean up that trailing hyphen in "Lote 14 -", etc.).
You may want move the export logic to its own separate function, as well, and then call that function from the DataTable config instead (so the logic does not clutter the DataTable configuration code).
Background information on this export function can be found here: exportData - specifically, see the format section on that page. This is the general buttons function used by the exportOptions configuration in the above example.

How to display timestamped data with PrimeFaces and ChartJs?

Since the public 7.0 release of PrimeFaces includes ChartJs, I thought I'd give it a try.
It works fine, however so far I have not been able to properly display data with values changing over time in a line chart.
chart.js has cartesian time axes for this purpose, however in PrimeFaces , only CartesianLinearAxes is available.
Feeding date objects (instead of String labels) to ChartData simply results in no x-axis being drawn.
Am I missing something or did they just skip this functionality when including chart.js in Primefaces?
OK great questions.
First, PF knows they did not implement time yet but there is an open ticket: https://github.com/primefaces/primefaces/issues/4564
Second, have no fear you can use the Extender feature to make it work. Here is an example we used.
In your Java model for your chart set the Extender feature on.
chartModel.setExtender("chartExtender");
In your XHTML add this JavaScript code function to match when you set in #1 Java bean.
function chartExtender() {
//copy the config options into a variable
var options = $.extend(true, {}, this.cfg.config);
options = {
//remove the legend
legend: {
display: false
},
scales: {
xAxes: [{
display: true,
type: "time",
time: {
parser: 'h:mm:ss a',
tooltipFormat: 'h:mm:ss a',
unit: 'hour',
displayFormats: {
'hour': 'h:mm:ss a'
}
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Your Y Axis',
fontSize: 13,
}
}]
}
};
//merge all options into the main chart options
$.extend(true, this.cfg.config, options);
};
You can see the different time formats available from ChartsJS using MomentJS.
Just a complement to do the extender works, use this.cfg.config.options = {...
for exemple:
function extName() {
this.cfg.config.options = {
legend: {
display: false
}
};
};

Kendo grid date filter localization

I try since one hour or more to change the localization of the date column filter type language. And I can't.
Here what I have :
On my _Layout : kendo.culture("fr-FR");
And when I load a page (anywhere on the app) :
But in the filter combo :
What is happening and what am I missing ?
Edit :
I forgot to say that the date filters are the only ones with this problem, string and number filters are correct.
You need to load in the French version of the Kendo message script file:
<script src="https://kendo.cdn.telerik.com/2017.2.504/js/messages/kendo.messages.fr-FR.min.js"></script>
Sample Dojo
EDIT
Dojo updated with date example.
NOTE: Date filter options are also in the specified language.
Found it !
I don't understand what exactly is the problem here...
I load the good culture file, number and string filters are ok, but not the date.
But in the kendo settings I have the good so...
$(document).ready(function () {
$(".k-grid").each(function () {
var grid = $(this).data("kendoGrid");
if (grid) {
grid.bind("filterMenuInit", onFilterMenuInit);
}
});
});
function onFilterMenuInit(e) {
if (this.dataSource.options.schema.model.fields[e.field].type === 'date') {
var filters = new Array();
var raw = kendo.ui.FilterMenu.prototype.options.operators.date;
for (var property in raw) {
if (raw.hasOwnProperty(property)) {
filters.push({ value: property, text: raw[property] });
}
}
e.container.find("select:eq(0)").data("kendoDropDownList").dataSource.data(filters);
}
}

Calculating total-items in AngularJs Pagination (ui.bootstrap) doesn't work correctly

I use controllerAs and avoid using the $scope as a model.
I want to add pagination in my search result. I have a paging object in my controller as below, which will be shared with angular service and then with the server API.
vm.paging = {
pageNumber: 1,
pageSize: 10,
totalCount: 0
};
totalCount will be set by server and then be read from response.
My pagination in html:
<pagination total-items="ctrl.pageCount"
items-per-page="ctrl.paging.pageSize"
ng-model="ctrl.paging.pageNumber"
class="pagination-sm"
boundary-links="true"
ng-change="ctrl.find()">
</pagination>
I calculate pageCount in controller as below:
vm.pageCount = function () {
return Math.ceil(vm.paging.totalCount / vm.paging.pageSize);
};
But it doesn't work. when I set vm.pageCount = 1000; it works. It seems the problem is the function. How can I fix this problem? (the buttons are disabled and It should return 100 pages, not one! )
Update: Sample Plunker
you CAN use an Immediately Invoked Function Expression (IFEE) to get your vm.pageCount like so
ctrl.pageCount = (function() {
return Math.ceil(ctrl.paging.totalItems / ctrl.paging.pageSize);
})();
but you don't need to calculate pageCount and put it under total-items (the amount of pages in the pagination will be calculated automatically), you should provide it the length of you record array instead!
lets say if you get table data vm.data from http, you should place the length of this data inside total-items like so
total-items="vm.data.length"
HTML
<uib-pagination total-items="ctrl.paging.totalItems"
items-per-page="ctrl.paging.pageSize"
ng-model="ctrl.paging.pageNumber"
class="pagination-sm"
boundary-links="true"
ng-change="ctrl.find()">
</uib-pagination>
JS
ctrl.paging = {
pageNumber: 1,
pageSize: 10,
totalItems: response.length // this is your remote data
};
I've made this plunker for you
EDIT 1
since version 0.14.0, the directives are prefixed by uib-
Since version 0.14.0 we started to prefix all our components. If you are upgrading from ui-bootstrap 0.13.4 or earlier, check our migration guide.
so you should also use uib-pagination (instead of pagination) because your plunk uses the 1.3.2 version.
I did it! Of course, with the guidance of my colleague :) . As in my plunk (script.js), I hadn't Initialized the vm.paging object after the response, so the computing was based on default values in vm.paging. Since totalCount was 0, always the Division result was 1 and I had just one page. So I edited the vm.find body as below:
vm.find = function () {
vm.result.length = 0;
vm.findingPromise = myService.find(vm.filter, vm.paging);
vm.findingPromise
.then(function (response) {
vm.result = response.data.result;
// EDITED PART:
vm.paging = response.data.paging;
//
}, function (response) {
var r = response;
ngNotify.set('Some problems occurred!',
{
type: 'error',
position: 'top',
sticky: true
});
});
And also, I couldn't take advantages of uib-pagination, but when I replaced ui-bootstrap-tpls-1.3.2.min.js anywhere I was using ui-bootstrap-tpls.min.js before, it works correctly.
Also I removed the function of computing pageCount. With many thanks to svarog.

Highcharts add series dynamically

I want to add some series (I get the series data from a webservice as a 3dim array (and returning it as json) - I dont know the number of series I will get, so I have to load the series data dynamically).
In javascript I am building an object: (like this highstock example: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo/compare/)
seriesOptions[i] = {
name: namearray[i],
data: dataarray
};
e.g. result: [Object { name="Series", data=[[1041375600000, 29,9]]}]
I was trying to add the series like this:
$.each(seriesOptions, function (itemNo, item) {
chart.addSeries({
name: item.name,
data: item.data
}, false);
});
chart.redraw();
But the chart draws the series kinda weird and doesnt convert to timestamp to date.
Are there any problems with my chart data from the webservice?
Here is my code: http://jsfiddle.net/DGdaf/2/
Thanks for any help so far.
EDIT
It seems like the chart ignoeres all the default values of timeline/zoom value.
I have no idea why it doesnt display these components.
The problem could be, that I am drawing the chart after the initialization?
chart = new Highcharts.Chart(options);
But I have to do it cause of the dynamic series loading.
EDIT2
I am not sure if I am loading too much data or something. I cant create my series dynamically.
for(i=0; i<seriesOptions.length; i++){
chart.addSeries({
name: seriesOptions[i].name,
data: seriesOptions[i].data
}, true);
};
Set for your yAxis:
yAxis: {
type: 'datetime'
}
See fiddle
EDIT:
Timeline / zoom
http://jsfiddle.net/DGdaf/5/
Edit:
Use callback to add series, when chart is ready. However, why don't you add these series when chart is created?
chart = new Highcharts.Chart(options, function(ch) {
$.each(seriesOptions, function (itemNo, item) {
ch.addSeries({
name: item.name,
data: item.data
}, false);
});
chart.redraw();
});