Reputation: 65
I am using kendo scheduler in MVC and when i tried to add custom button in it, that successfully working but when i resize window it showed me multiple times.
I attached screenshot of my page...here button is shown multiple times..so what is the solution to this to resolve.
here, is my code for scheduler.
<script id="groupHeaderTemplate" type="text/x-kendo-template">
<div>
<input class="dropdowntree" />
</div>
</script>
<div id="scheduler">
@(Html.Kendo().Scheduler<BusSchedulingSystem.Web.ViewModels.SchedulerViewModel>()
.Name("scheduler")
.Date(DateTime.Now)
.StartTime(new DateTime(2018, 1, 1, 6, 00, 00))
.Views(views =>
{
views.TimelineMonthView(e => e.EventHeight(50));
})
.Timezone("Etc/UTC")
//.DataSource(d => d
//.Read(read => read.Action("", ""))
// )
//.GroupHeaderTemplate("#= BindDropDownTree(data)#")
.GroupHeaderTemplateId("groupHeaderTemplate")
.Group(group => group.Resources("Company").Orientation(SchedulerGroupOrientation.Vertical))
.Events(events => events.DataBound("onLoad"))
.Resources(resource =>
{
resource.Add(m => m.Company.Id)
.Title("Company")
.Name("Company")
.DataTextField("Name")
.DataSource(ds => ds
.Custom()
.Transport(transport => transport.Read(read => read.Action("Read", "Scheduler")))
.Schema(schema => schema
.Data("Data")
.Total("Total")
)
);
})
)
</div>
and my onload function is :
<script>
function onLoad(e) {
debugger
$('.k-nav-current').hide();
var scheduler = $("#scheduler").data("kendoScheduler");
var btn = $("<button class='k-button k-my-button'>Add new tour</button>")
$('#scheduler').find('.k-scheduler-toolbar').append(btn);
btn.click(function () {
document.location = '@Url.Action("AddTour", "Tour")'
});
//var checkbox = $('<input checked type="checkbox" value="1">');
//$('#scheduler').find('.k-scheduler-toolbar').append(checkbox);
}
</script>
Upvotes: 0
Views: 224
Reputation: 1669
Obviously my colleague had the same issue once. This is what I found in our repository:
var buttonSet = 0;
function addCreateButtonToAgendaView() {
if (buttonSet === 0) {
buttonSet = 1;
var button = $("<a class='k-button k-my-button'>@Resources.BtnNewTask</a>");
$(getScheduledTasksGrid().toolbar).append(button);
button.click(function () { $("#scheduler").getKendoScheduler().addEvent(); });
}
}
So you have to set a marker if you've already added the button or not.
(In my original answer, I've accidentally looked into the TreeList instead of the Scheduler. Sorry.)
Upvotes: 1