Single calendar Date Range Picker - date-range

I am looking to build a date range picker that's values only consist of January-December of a single year at a time.It will look something like this:
(This is taken from my existing kendo date range picker and poorly photoshopped)
I have built one using the kendo date picker but it seems to require two calendars, one for start date and the other for end date. Being that my range can only span months in a single year, I just need one calendar like below where the user can either click and drag for the desired range, or they can just click two dates. Does anyone know of a date range picker that already functions this way? Or if there is a way to alter the kendo one to do the same?
Thanks.
Edit: Here is my code for my existing date range picker:
var start = $("#StartDate").kendoDatePicker({
value: LastMonthString,
format: "MM/yyyy",
start: 'year',
depth: 'year',
change: startChange,
open: function() {
$('#StartCalendar').append($('#StartDate_dateview'));
},
close: function(e) {
e.preventDefault();
}
}).data("kendoDatePicker");
var end = $("#EndDate").kendoDatePicker({
value: TodaysDateString,
format: "MM/yyyy",
start: 'year',
depth: 'year',
change: endChange,
open: function() {
$('#EndCalendar').append($('#EndDate_dateview'));
},
close: function(e) {
e.preventDefault();
}
}).data("kendoDatePicker");
start.max(end.value());
end.min(start.value());
$("#StartDate").attr("readonly", true);
$("#EndDate").attr("readonly", true);
start.open();
end.open();

This is how I've made it to show years only but you can change the format obviously
$('#sandbox-container').datepicker({
format: "yyyy",
startView: 1,
viewMode: "years",
minViewMode: "years",
minViewMode: "years",
multidate: true,
multidateSeparator: ", ",
autoClose: true,
}).on("changeDate",function(event){
var dates = event.dates, elem = $('#sandbox-container');
if(elem.data("selecteddates") == dates.join(",")) return; //To prevernt recursive call, that lead to lead the maximum stack in the browser.
if(dates.length>2) dates=dates.splice(dates.length-1);
dates.sort(function(a,b){return new Date(a).getTime() - new Date(b).getTime()});
elem.data("selecteddates",dates.join(",")).datepicker('setDates', dates);
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css" media="screen">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<div id="sandbox-container">
<input type="text" id="date" value="">
</div>

Related

How to prevent tabulator input to close when clicking elsewhere

I have a custom datepicker calendar I want to show for editing dates in tabulator. I have managed to open the calendar when the row cell is click by providing a custom editor.
The problem is that as soon as I click on my calendar, (what I think happens) is that Tabulator´s "As a fallback Tabulator will cancel the edit if an editor is blured and the event has not been correctly handled." behavior triggers before I can process the click on my calendar and update the cell value.
Is there a way to allow the user to click on the calendar without making tabulator cancel the edit?
Don't know which custom date picker you are using but here is a working example using flatpickr:
let initialTableData = [{
eventName: "Christmas party",
eventDate: "12-25-2021"
},
{
eventName: "New Years party",
eventDate: "12-31-2021"
}
]
function dateEditor(cell, onRendered, success, cancel, editorParams) {
let editor = document.createElement("input")
editor.value = cell.getValue()
let datepicker = flatpickr(editor, {
dateFormat: "m-d-Y",
onChange: setDate,
onClose: setDate
})
function setDate(selectedDates, dateStr, instance) {
success(dateStr)
instance.destroy()
}
onRendered(() => {
editor.focus()
})
return editor
}
let eventTable = new Tabulator("#eventTable", {
data: initialTableData,
columns: [{
title: "Event",
field: "eventName",
width: 200
},
{
title: "Event Date",
field: "eventDate",
editor: dateEditor
}
]
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/5.0.7/js/tabulator.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.9/flatpickr.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/5.0.7/css/tabulator.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css" rel="stylesheet" />
<div id="eventTable"></div>
Here is the CodePen

Flatpickr min/maxTime options not being set correctly

having an issue where the min or max time I set is not applied when you first open the window, or anytime I update the config dynamically after it's first created. In this example you can see it's set to be 1:00 PM minTime, but it shows 12:00 PM when toggled open. Closing the picker will correct itself to then show 1:00 PM.
const fp = flatpickr(".date", {
enableTime: true,
noCalendar: true,
minTime: '13:00',
dateFormat: 'h:i K',
});
https://jsfiddle.net/dkgxuw4r/
I noticed it works as expected on the doc site: https://flatpickr.js.org/examples/#time-picker-w-limits, but not when I use those same exact options. So how to achieve this?
You can set the default hour to 13, in this way its already updated on initialization.
To do this you can use the Flatpickr config option defaultHour: 13,.
Example
$(document).ready(function() {
const fp = flatpickr(".date", {
enableTime: true,
noCalendar: true,
defaultHour: 13,
minTime: '13:00',
dateFormat: 'h:i K',
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.11/flatpickr.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.11/flatpickr.min.js"></script>
<input type="text" placeholder="Select Date.." class=date>

How can I pass External date filters Inside the Embedded HTML Page

How can I pass External date filters(Like start and end date), inside the custom HTML Page so that report gets rendered when I pass those values and clicks on submit I have the below HTML Page which gives a embedded report but I am trying to work those input box's how can I do this?
Is this possible or still present inside the ideas tab? Please guide my on it as How should I achieve this?
My HTML Code:-
<html>
<body>
<h2>PowerBI Embedded Report</h2>
<form action="/action_page.php">
<input type="text" name="sdate" placeholder="Start Date"><br>
<input type="text" name="edate" placeholder="End Date"><br>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
window.onload = function () {
var models = window['powerbi-client'].models;
var embedConfiguration = {
type: 'report',
accessToken: 'H4sIAAAAAAAEAC2Wx8rGDHaD7-XfOuDeArNw7717Z7_uvbeQe88XZvaCA8-RhP7nHzt7hzkr_vnvf0wUrmKBLexiTDSgmbSBLCFMqVC6-C2i2HSVSJG9OiWtTMjFe-ozi5tfZwsJuH3jRKiWsWGkrJ8kTbfMnVzTj4OKVV9RRz7RZpAwcm40K-EEJQtxbTXppsVoOEkOSnS_vLLEuOgmXJVLj4Z-mVWAoP93FnZcFOOtt5qIh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da_OwarS8bYACiFKT6fmJ0JpHnT0nLFWqIQN6xHvCZOTm4Y_4Hxj03_1oQZcmDgSZs1Iqz9ANESlLYkDtOMjMvrzrBC8c1qCLmWa4nJI4ldKIp7oPwrdrTGEuaiYi8WODETWCqq_QfzuzTlpoR_lMXoMToQpp6Y75VyYpir6Zx_q7y2nrLj3Mo_WVn8mGR68N4UIbiemwf7WzE5BXNkUiFc0_ayqynxmcbVT7SERI5Q7ew7GfPXom9z0GZBvgVFY8Jl2wBy1oJx5dh7O1yBNZU7yvURaM7GCqJSl99qZOUo04LrPfGcsuEND9SDykxfvpQFbPel7RBlFgsdLdOz-YhcqxHKtEEYZcIfMLDpI9h1b7Dx8TQ5bLr-2nkfhfPgzHXHd2goAFT1B6Uhf0zWcvUUkZ43_5w5ZfaFyfm9dO7k7COMT5sbuZguvkNLdHMwS6qVWXKjBktgbmbyzE2u3lAmMwN88YDl-mCCz5upiqPkCGSOu7Lmi0Q5YP1m98f3h06UeweqzeumWVB1_Yf5f_8PAgjN0hoLAAA=',
id: 'cd0cbb78-41ca-4db1-b739-e982f59694a2',
tokenType: models.TokenType.Embed,
embedUrl: 'https://app.powerbi.com/reportEmbed?reportId=cd0cbb78-41ca-4db1-b739-e982f59694a2&groupId=a78aa4c1-fa2f-4e4d-b21e-3d47bb89618e'
};
var report;
var $reportContainer = $('#reportContainer');
report= powerbi.embed($reportContainer.get(0), embedConfiguration);
var Filter1 = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "reporting_validation_agg_group",
column: "aggregation_end_date_local_1"
},
logicalOperator: "AND",
conditions: [
{
operator: "LessThanOrEqual",
value: "12/20/2017"
}
]
}
var Filter2 = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "reporting_validation_agg_group",
column: "aggregation_end_date_local_1"
},
logicalOperator: "AND",
conditions: [
{
operator: "GreaterThan",
value: "12/10/2017"
}
]
}
report.on('loaded', event => {
report.getFilters()
.then(filters => {
filters.push(Filter1);
filters.push(Filter2);
return report.setFilters(filters);
});
});
}
function reloadreport(){
var $reportContainer = $('#reportContainer');
powerbi.embedNew($reportContainer.get(0), embedConfiguration);
};
</script>
<script src="jquery.js"></script>
<script src="es6-promise.js"></script>
<script src="powerbi.js"></script>
<div id="reportContainer"></div>
</body>
</html>
See if this solution helps you too:
https://community.powerbi.com/t5/Desktop/Power-BI-JavaScript-filter-between-2-dates/td-p/312204
Basically, you define an ADVANCED filter with the 'AND' operator referring to the intersection of the 2 dates.
You would, however, need to parse your input text (or datepicker) to the format required by the filter..
Please note that you can define the filters as part of the loadConfig by using the property filters: [filter1, filter2] as well..

Kendo Grid Excel Export with Columns with DropDown Template

I want to export the kendo grid data into excel. I am using kendo dropdownlist as a template for some columns.
When i export it exports but it not show the text value for those columns but rather shows value for that fields.
This may not be the "best" solution but it worked for me. Basically I created a function that loops through and processes the row with the dropdown, using a switch statement to set the text based on the value (the data that comes through unfortunately only has the value, rather than the object).
Here is the markup for my grid:
<div id="grid" data-role="grid"
data-sortable=" {mode: 'single' , allowunsort:true }"
data-toolbar="[{template: this.model.getToolbar}]"
data-excel="{ fileName: 'export.xlsx', allPages:'true' }"
data-excel-export="model.curateExcelData"
data-columns="#string.Format(#"[
{{ title:'{0}', field: 'Column1', width:80 }},
{{ title:'{1}', field: 'Column2', width:80 }},
{{ title:'{12}', field: 'DropDownColumn',template: kendo.template($('#dropdown-template').html()),'width':80, sortable: false }},
]", CommonResource.Column1, CommonResource.Column2, CommonResource.DropDownColumn)"
data-bind="source: items"
data-editable="inline">
</div>
And the template:
<script id="dropdown-template" type="text/x-kendo-template">
<input data-role="dropdownlist"
data-auto-bind="false"
data-value-primitive="true"
data-text-field="Text"
data-value-field="Value"
data-bind="value: dropDownValue, source: dropDownValues"
style="width:65px" />
</script>
And here is the function that updates the values for the export (in my case I had a dropdown that was "Days" and "Weeks", which was the 12th column):
curateExcelData: function (data) {
var sheet = data.workbook.sheets[0];
$.each(sheet.rows, function (index, row) {
if (row.type == "data") {
switch (row.cells[12].value) {
case "D":
row.cells[12].value = "Days";
break;
case "W":
row.cells[12].value = "Weeks";
default:
break;
}
}
});
},

Kendo datepicker is dispalying date in long format with time how to avoid it

This is code I am using can be seen by clicking the this link
http://jsfiddle.net/fGq5w/1/
On click of the button , I change the date. But the time is also displayed.
How to display one date alone when i click the button.
HTML CODE
<input id="myDatePicker" data-bind="value: currentDate" />
<h2>Current Date is:<strong data-bind="text: currentDate"></strong></h2>
<input type='button' value='change Date' onclick='changeDate();return false;' />
Javascript
var vm = {
currentDate: ko.observable()
};
$(function(){
ko.applyBindings(vm);
$("#myDatePicker").kendoDatePicker();
});
function changeDate()
{
alert('ok');
vm.currentDate(new Date(2014,1,1));
}
This is more of a Kendo question. Just format the date with kendo's date formatting tools:
http://docs.kendoui.com/getting-started/framework/globalization/dateformatting
eg...
vm.currentDate(kendo.toString(new Date(2013,0,1), "MM/dd/yyyy"));
Your Code with additional functionality to pre-fill the date TextBox.
var vm = {
currentDate: ko.observable(kendo.toString(new Date(),'MM/dd/yyyy'))
};
$(function(){
ko.applyBindings(vm);
$("#myDatePicker").kendoDatePicker();
});
enter code here
function changeDate()
{
alert('ok');
vm.currentDate(kendo.toString(new Date(2014,1,1),'MM/dd/yyyy'));
}
In Knockout 3.3.0, you can create an extension to handle the formatting since calling a function manually isn't terribly ideal:
(In the snipper below I'm using moment.js to parse the date, but you could use kendo's date parser - although it doesn't work with certain ISO formatted dates)
ko.extenders.stripTime = function (target) {
var result = ko.pureComputed({
read: target,
write: function (value) {
if (value) {
target(moment(value).format(shell.getDateFormatString()));
}
else {
target(value);
}
}
}).extend({ notify: 'always' });
result(target());
return result;
};
In your client-side viewmodel, apply the extension to your observable:
self.SomeDateProperty = ko.observable().extend({ stripTime: null });
I recommend not using ko.toJS when you try to get a javascript object from your observables when using kendo datepicker - Instead, use ko.mapping (you need to download the JS library separately).
var someJavascriptObject = ko.mapping.toJS(viewModel);

Resources