How to add holidays to kendo scheduler? - kendo-ui

Is anybody know how to add holidays to kendo scheduler?
I mean in a holiday user shouldn't be able to add any events.

I suggest to add a custom class in my example i created class k-holiday or maybe utilize kendo class k-non-workhour and on dataBound function add this :
dataBound: function () {
var scheduler = this;
//get scheduler view
var schedulerView = this.view();
//loop through all slot/event/tile
schedulerView.table.find("td[role=gridcell]").each(function () {
//find start date
var slot = scheduler.slotByElement($(this));
var CONSTANT_HOLIDAY_DATE = new Date("2013/6/11");
CONSTANT_HOLIDAY_DATE.setHours(0, 0, 0, 0);
slot.startDate.setHours(0, 0, 0, 0);
//compare date curent event with holiday
if (slot.startDate.getTime() == CONSTANT_HOLIDAY_DATE.getTime()) {
$(this).addClass("k-holiday");
} else {
$(this).removeClass("k-holiday");
}
});
},
i created a holiday on this particular Date new Date("2013/6/11") where later on all event/slot on this date will have k-holiday class, then you want to add this to your edit function :
edit: function (e) {
var uid = e.container.attr('data-uid');
var element = e.sender.element.find('div.k-event[data-uid="' + uid + '"]');
var slot =$("#scheduler").data("kendoScheduler").slotByElement(element);
if($(slot.element).hasClass("k-holiday")){
e.preventDefault();
}
}
above condition will filter event that is double clicked / edited , where it will prevent the event that has k-holiday to open the popup. Please refer to this kendo dojo
Note : on that example you will notice that on tuesday 6/11 you can't trigger the edit/add new event, but on the day other than that you still can

You can use the all day event template to create holidays.
The message can be set through messages.allDay like this:
<div id="scheduler"></div>
<script>
$("#scheduler").kendoScheduler({
date: new Date("2013/6/6"),
messages: {
allDay: "Holiday"
},
dataSource: [
{
id: 1,
start: new Date("2013/6/6 08:00 AM"),
end: new Date("2013/6/6 09:00 AM"),
title: "Interview"
}
]
});
</script>
You can check this executable example with holiday details.
Edit
BorHunter: but in your example I can add new events into scheduler, but I don't need it. I mean user shoudn't be able to add event on that particular holiday/date.
Then you just disable that option by using editable like this example that has:
editable: false,
Or this one:
editable: {
create: false,
update: false,
resize: false,
move: false,
destroy: false
},

Related

Export to PDF increase number of items per page

I have a grid control which I wish to export the content of. Upon initialisation, the pageSize attribute is set to 10 items however I want to increase the number of items per page during exportToPDF.
I have tried to modify the pageSize of the dataSource prior to carrying out the export but this seems to have no effect on the end product.
var grid = $("#grid").data("kendoGrid");
var filter = grid.dataSource.filter;
grid.dataSource.query({
filter: filter,
pageSize: 20, // has no effect on the exported PDF
page: 1,
group: [{
field: "groupField1",
dir: "asc"
}, {
field: "groupField2",
dir: "asc"
}, {
field: "groupField3",
dir: "asc"
}]
});
var progress = $.Deferred();
grid._drawPDF(progress)
.then(function (root) {
return kendo.drawing.exportPDF(root, { forcePageBreak: ".page-break", multiPage: true });
})
.done(function (dataURI) {
// ... do some manual manipulation of dataURI
kendo.saveAs({
dataURI: manipualtedDataURI
});
progress.resolve();
Is there something I am missing so I can display more items on each page of the PDF export?
EDIT
Including my grid definition with the pdfExport function suggested by the below answer (which never gets called):
var grid = $("#reportGrid").kendoGrid({
pdf: {
allPages: true,
avoidLinks: true,
repeatHeaders: true,
template: kendo.template($("#page-template").html()),
scale: 0.7,
margin: { top: "2.5cm", right: "1cm", bottom: "1.5cm", left: "1cm" },
paperSize: "A4",
landscape: true
},
// *this function is not getting called*
pdfExport: function(e) {
e.sender.dataSource.pageSize(10);
e.promise.done(function() {
e.sender.dataSource.pageSize(20);
});
},
toolbar: kendo.template($("#template").html()),
...
});
Note: A template is used to include a header / footer on each page of the PDF export.
Another note: 'Manual manipulation of dataURI' includes going out to the server to perform a merge with another PDF file, so I cannot use the default export via the grid :(
EDIT 2
I have extended the Dojo example from #R.K.Saini's answer to use the method by which I need to generate the PDF export (as per original post).
The snippet logs the URI of the grid being exported and when the pdfExport function is called. As you will see, when using the built in grid 'Export to PDF' button, the pdfExport function is triggered but when using the additional button below the grid, it is not.
You can use pdfExport event to change page size of your grid datasource before pdf export started and then when the export finish you just need to revert back the previous page size.
The call back function of this event receive grid instance as e.sender and and a promise as e.promise which can be used to set back the page size when exporting finish.
For more info check http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-pdfExport
$("#grid").kendoGrid({
dataSource: dataSource,
pdf: {
allPages: true
},
pdfExport: function(e) {
e.sender.dataSource.pageSize(10);
e.promise.done(function() {
e.sender.dataSource.pageSize(20);
});
},
...
//Other configguration
});
Here is a working demo http://dojo.telerik.com/UzOXO
Edit
You can also change grid page size in your custom export function just change grid page size before calling _drawPdf() function and change it back when done.
$("#btnPdfExport").kendoButton({
click: function () {
var grid = $("#grid").data("kendoGrid");
var progress = $.Deferred();
// Change grid datasource pagesize before calling _drawPDF
grid.dataSource.pageSize(20);
grid._drawPDF(progress)
.then(function (root) {
return kendo.drawing.exportPDF(root, { forcePageBreak: ".page-break", multiPage: true });
})
.done(function (dataURI) {
console.log("Exporting " + dataURI);
kendo.saveAs({
dataURI: dataURI,
fileName: "export.pdf"
});
progress.resolve();
// Change grid datasource pagesize when done
grid.dataSource.pageSize(10);
});
}
});
Check Update DOJO here http://dojo.telerik.com/UzOXO/8

how to select all records in the grid in order to export the data

I am trying to select all the data present in the jqgrid table in order to export in to an excel file. But the data present in the first page of the grid is only getting exported. i.e., if a total of 25 records are present in the grid and 5 records are present in the first page, then only first 5 records are getting exported.
The following code is responsible for displaying records 'only' in the first page of the grid..
var gridData = $("#list").jqGrid('getRowData');
The following code is responsible for displaying records present in all the pages in the grid..
var gridData1 =jQuery("#list").jqGrid('getGridParam','data');
how to use the above code such that I can select all the records present in the grid. also, I am trying to apply filter on the records present in the grid. In such a case, how to get the filtered number of records in order to export them..?
Thanks,
You can do it server side.
<script type="text/javascript">
$(document).ready(function () {
$('#list').jqGrid({
caption: "test",
// ...
}).navGrid(
// ...
}).jqGrid('navButtonAdd', '#pager', {
caption: "", buttonicon: "ui-icon-print", title: "export",
onClickButton: function () {
$("#list").jqGrid('excelExport', { url: 'path......' });
}
});
});
</script>
excelExport method, sends the current page number, sort field, filtering, etc to the specified url. now you have time to process these parameters and create a new output.
You may want to try below script and function:
<script type='text/javascript'>
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.outerHTML }
window.location.href = uri + base64(format(template, ctx))
}
})();
$(document).ready(function () {
...declare & setup the jqGrid with 'big row page', e.g. ...
rowNum: 9999,
rowList: [50, 100, 200, 9999],
.........then add below navigation button after setup the grid...
$("#list").jqGrid('navButtonAdd', pgrid1, {caption:"Download",title:"Download report contents", buttonicon :'ui-icon-circle-arrow-s',
onClickButton:function(){
tableToExcel('list', 'export data')
}
});
}
</script>
Alternatively, another way to exporting can refer to related question:
How to enable jQgrid to Export data into PDF/Excel

KendoScheduler change event not firing

I'm having trouble with the Kendo Scheduler widget. The app is working and loading data in our app but will not fire the change event. Have copied the basic scheduler setup from the demo into a fiddle and still no dice. Need a second set of eyes, thanks.
References:
1.Kendo Scheduler Demo w events
2.Kendo Scheduler change event doc
<div id="displayEvent"></div>
<div id="apptList"></div>
==========================================
$('#apptList').kendoScheduler({
views: [
{ type: 'day', selected: true },
'week',
'month'
],
allDaySlot: false,
startTime: new Date(new Date().setHours(7, 0, 0, 0)),
selectable: true,
change: function (e) {
$('#displayEvent').text('Change called');
var start = e.start; //selection start date
var end = e.end; //selection end date
var slots = e.slots; //list of selected slots
var events = e.events; //list of selected Scheduler events
var message = "change:: selection from {0:g} till {1:g}";
if (events.length) {
message += ". The selected event is '" + events[events.length - 1].title + "'";
}
$('#displayEvent').text(message);
}
});
$('#displayEvent').text('Where are my events?');
Apparently, this was a problem specific to build 2013.2.918. I upgraded to build 2013.3.1119 and the events are now working.

ExtJS4 dataView - Select node id

I have an ExtJS 4 dataView and i would like to catch the id of a selected node.
It is the first time that i'm using the dataView, then, there are some troubles.
The store is loaded correctly and i see the datas into the view very well. The problem which i'm having, concern the "classic" actions of update and delete, particularly getting the id of a selected item.
For example into a grid i click, then select a record and through a button's pressing i open a window (or other actions) with a loaded form (by sending in AJAX to the store, the id of the selected row) and i update the datas.
I'm not still able to do it with the ExtJS 4 dataView.
Below my dataView:
dataView_player = Ext.create('Ext.Panel', {
id: 'images-view',
frame: true,
collapsible: false,
autoWidth: true,
title: 'Giocatori (0 items selected)',
items: [ Ext.create('Ext.view.View', {
id:'players-view',
store: store_player,
multiSelect: true,
height: 310,
trackOver: true,
overItemCls: 'x-item-over',
itemSelector: 'div.thumb-wrap',
emptyText: 'Nessun giocatore visualizzato',
tpl: [
'<tpl for=".">',
'<div class="thumb-wrap" id="{id}-{name}">',
'<div class="thumb">',
'<img src="/img/players/{picture}" title="{name} {surname}" alt="{name} {surname}" style="">',
'</div>',
'<span class="" style="height:30px;">{general_description}{name} {surname}</span>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>'
],
plugins: [
Ext.create('Ext.ux.DataView.DragSelector', {}),
Ext.create('Ext.ux.DataView.LabelEditor', {dataIndex: 'name'})
],
prepareData: function(data) {
Ext.apply(data, {
name: data.name,
surname: data.surname,
general_description: Ext.util.Format.ellipsis(data.general_description, 15)
});
return data;
},
listeners: {
'selectionchange': function(record, item, index, e) {
var node = this.getNode(record); //this.getNode(record);
console.log(node.get('id'));
}
}
}) ],
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'delete',
text: 'Cancella Selezionati',
scale: 'medium',
tooltip: 'Per <b>cancellare</b> i giocatori selezionati',
tooltipType: 'qtip',
id: 'delete-player',
disabled: true,
handler: delete_news
}, '-', {
iconCls: 'edit',
text: 'Aggiorna Selezionata',
scale: 'medium',
tooltip: 'Per <b>aggiornare</b> un giocatore selezionato',
tooltipType: 'qtip',
disabled: false,
id: 'update-player',
handler: function(nodes) {
var l = nodes.get('id');
console.log(l);
}
}
}
]
}]
});
Of course, this is a wrong example (because the listeners don't work) but it's just to make an idea.
There are two main things what i would like to do:
1) Catch the id (and other store's fields) of the selected item on the action "selectionchange". Obviously, now it doesn't work because of this: node.get('id'). Of course it's a wrong syntax but make up the idea of my will.
2) Catch the id of the selected item on the handler event of the "update-player" button. As above, the issue is the nodes.get('id'). Further trouble, is how to pass the selected item's features. in handler: function(nodes) { the nodes variable does not assume any value and i don't know how to pass the params from the dataview to the handler function.
I hope that somebody will able to help me.
According to the docs the selectionchange event provides the selection model as well as the array of selected records, so you are probably assuming the wrong parameters in your listener.
Without doing further testing, I think it should be something like this:
listeners: {
'selectionchange': function(selModel, selection, eOpts) {
var node = selection[0];
console.log(node.get('id'));
}
}
Note that you're using multiSelect: true, so it could be more than one record in the selection array.
Answer for second part of the question:
In button handler, you need to get selection model of the view and from it get information about selected records:
handler: function(nodes) {
// find view component
var view = dataView_player.down('dataview');
// get all selected records
var records = view.getSelectionModel().getSelection();
// process selected records
for(var i = 0; i < records.length; i++) {
console.log(records[i].getId());
}
}

Sencha Touch - how to prevent a datepicker from hiding?

I'm using an Ext.picker.Date and I have some checks I run on the hide event. However, if a certain criteria is met, I want to stop the process and have the date picker not hide.
I've tried using the beforehide event, and running my code there, but that event doesn't seem to fire.
Below is the config for my datepicker. If the condition is true, how can I stop the picker from hiding?
Thanks for any help.
var datePicker = new Ext.picker.Date({
docked: "bottom",
listeners: {
beforehide: function() {
console.log("before hide");
},
hide: function() {
if (1 == 1) {
//how do I stop the picker from hiding?
Ext.Msg.alert("You cannot select that date.");
}
}
},
slotOrder: ["day", "month", "year"],
useTitles: false
});
this.add(datePicker);
Are you using Sencha Touch 2? I'm going to assume so, since you're using Ext.picker.Date.
According to the documentation, the date picker doesn't fire a beforehide event:
Sencha Docs
What you really want to do here is insert some logic after 'Done' is tapped and before the picker hides itself. The picker calls onDoneButtonTap internally; you can inject your own logic like so:
Ext.define('MyApp.widget.DatePicker', {
extend: 'Ext.picker.Date',
xtype: 'mypicker',
onDoneButtonTap: function() {
if (1 == 1) {
Ext.Msg.alert("You cannot select that date.");
} else {
Ext.picker.Date.prototype.onDoneButtonTap.call(this);
}
}
});
this.add({
xtype : 'mypicker',
docked : "bottom",
slotOrder : ["day", "month", "year"],
useTitles : false
});
This is assuming that your logic will be able to access what it needs within the scope of the date picker. If this isn't the case, you can pass additional configuration to the date picker when you create it...maybe something like acceptedDateRange {...}
The simplest way could be:
var datePicker = new Ext.picker.Date({
docked: "bottom",
slotOrder: ["day", "month", "year"],
useTitles: false,
onDoneButtonTap: function() {
if (1 == 1) {
Ext.Msg.alert("You cannot select that date.");
} else {
Ext.picker.Date.prototype.onDoneButtonTap.call(this);
}
}
});
this.add(datePicker);
I think defining your own class like in the first example is the way to go, especially in situations where you inject logic into existing framework code and when you use the component in more than one place. But the second example will work as well.

Resources