I have a chart with many colors. The tooltip should appear as black or white depending on the background color of the chart's bar. The only option I can think of is handle this with the series.name. But nothing works.
This code does accurately put a white or a black piece of text onto the screen as a tooltip:
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("# if ((series.name === 'foo') || (series.name === 'bah')) { return '<strong style=\"color: black\">bar</strong>'; } else { return '<strong style=\"color: white\">bar</strong>'; } #")
)
However, once I plug in #= series.name # #= value # instead of bar the function breaks down and it no longer works.
Next, I tried both SharedTemplate and Template as such (one at a time of course):
.Tooltip(tooltip =>
tooltip.Visible(true).Template("mytemplate")
tooltip.Visible(true).SharedTemplate("mytemplate")
)
<script id="mytemplate" type="text/x-kendo-template">
# if ((series.name === 'foo') || (series.name === 'bah')) { #
<strong style="color: black">bar</strong>
# } else { #
<strong style="color: white">bar</strong>
# } #
</script>
This didn't do anything and instead displayed a tooltip of "mytemplate".
Is this possible to do? If not is there any kind of work around?
hello, I have using the scheduler and when I inspect the control in the javascript console I can see that there is data in the resources.datasource object but for some reason the resources are not displaying in the Timeline. I'm just trying to load resources right now without events. Do I have to have events for the resources to load properly. In the old webforms scheduler you didn't need that. Also, once loaded how do I change them dynamically so that users can manipulate the timeline and look at specific combination of resources.
@(Html.Kendo().Scheduler<Avianis.Models.Scheduler.AppointmentViewModel>()
.Name("scheduler")
.Date(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
.Views(views =>
{
views.TimelineView(timeline => timeline.EventHeight(50));
views.TimelineWeekView(timeline => timeline.EventHeight(50));
views.TimelineMonthView(timeline => timeline.EventHeight(50));
})
.Resources(resource => resource.Add(m => m.ResourceID)
.Title("Aircraft")
.Name("Aircraft")
.DataTextField("Name")
.DataValueField("ID")
.DataSource(source => source
.Read("GetResources", "Calendar"))
)
.DataSource(d => d
.Model(m =>
{
m.Id(f => f.MeetingID);
m.Field(f => f.Title).DefaultValue("No title");
m.RecurrenceId(f => f.RecurrenceID);
m.Field(f => f.Title).DefaultValue("No title");
})
.Read("Aircraft_Read", "Calendar")
)
)
Hello, is there an option to remember the state of checkbox'ed items in the TreeView when loading them from the server? Such as when repopulating a complex control the TreeView is a part of?
Thanks in advance for your speedy reply, Telerik! :)
I’m using MVC Kendo grid and few drop down lists as filters and search button. Grid is bound using Ajax. The filters are defined outside of the grid. When user clicks on the search button i am passing the selected filter values to action method as Model, do the search and return the result. This is working fine when user selects the filter.
However, One of the filter is required filter, so I have [Required] attribute on the model’s property. When user don’t select the required filter, it makes the GetData() action method as expected, I see ModelState is NOT valid as expected.
But here im not sure what should I return when Model is not valid,
Questions:
I have validation summary on the layout page, how do I show model error in ValidationSummary without clearing the grid?When action method returns error, I don’t want to clear the existing result in the Grid. The error should display on top of the page.
Note: For brevity purpose my sample below showing only one filter. Also I’m not worrying about client side validation.
Layout Page
<
html
>
<
head
>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/kendo/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/kendo")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryval")
</
head
>
<
body
>
<
div
class
=
"container body-content"
>
@Html.ValidationSummary()
@RenderBody()
<
footer
></
footer
>
</
div
>
@RenderSection("scripts", required: false)
</
body
>
</
html
>
Index Page
@model MyModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<
h2
>Index</
h2
>
<
div
>
<
br
/>
@Html.ListBoxFor(x => x.SelectedIDs, new MultiSelectList(Model.States, "ID", "Name"))
@Html.ValidationMessageFor(m => m.SelectedIDs)
</
div
>
<
input
id
=
"btnSearch"
type
=
"submit"
width
=
"100"
value
=
"Search"
/>
@(Html.Kendo().Grid<
Person
>()
.Name("grid")
.Columns(col =>
{
col.Bound(p => p.ID);
col.Bound(p => p.Name);
})
.DataSource(ds =>
ds.Ajax()
.Read(r => r.Action("GetData", "Working"))
.PageSize(3))
.Pageable()
.Sortable()
.AutoBind(false)
)
<
script
src
=
"~/Scripts/Working.js"
></
script
>
JavaScript
$(
function
() {
var
myModel = {
SelectedIDs: []
};
var
dataSource = $(
"#grid"
).data(
"kendoGrid"
).dataSource;
dataSource.transport.options.read.data = getFilters;
$(
"#btnSearch"
).click(
function
() {
myModel.SelectedIDs = $(
"#SelectedIDs"
).val();
$(
"#grid"
).data(
"kendoGrid"
).dataSource.read();
$(
"#grid"
).data(
"kendoGrid"
).refresh();
})
function
getFilters() {
return
myModel;
}
})
Controller
public
class
WorkingController : Controller
{
public
ActionResult Index()
{
var model =
new
MyModel();
return
View(model);
}
public
ActionResult GetData([DataSourceRequest]DataSourceRequest request, MyModel model)
{
if
(!ModelState.IsValid)
{
// What should i return here so that Model error message will appear in ValidationSummary ???
}
return
Json(MockData.GetPersons().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
}
Model
public
class
MyModel
{
[Required(ErrorMessage =
"State is required."
)]
public
int
[] SelectedIDs {
get
;
set
; }
public
IEnumerable<State> States
{
get
{
return
MockData.GetStatesWithAbbr();
}
}
public
IEnumerable<Person> Persons {
get
;
set
; }
}
01.
Html.Kendo().Grid<dynamic>()
02.
.Name(
"grid"
)
03.
.Filterable(filter => filter.Enabled(
false
))
04.
.DataSource(ds => ds.Ajax().Read(read => read.Action(
"action"
,
"controller"
)))
05.
.Columns(columns =>
06.
{
07.
columns.Bound(
"field"
)
08.
.Title(
"title"
)
09.
.Sortable(
true
)
10.
.HeaderTemplate(
"???"
);
11.
});
Hi All
I'm trying to start using my license, but I'm doing something wrong for sure.
I copy to my page of a project that is working, the following script from a new project create thru template Telerik \Web\c# ASP.NET MVC Application, from Index.cshtml. (@(Html.Kendo().PanelBar()..."
But I don't have any change, I move the mouse over the bar, and I saw the new bar, but nothing happen when I click over that position.
I suppose is missing some bundles, but I don't know what js is missing.
In the new project everything works well, but not in my.
Any clue what I must do?
Paulo Afonso
Hi,
I am using the ASP.NET MVC Grid control on a page. The functionality is to fire a AJAX query when a Grid row is selected. The AJAX query calls the MVC Controller and gets a response HTML.
The response HTML is a Tab Strip with 4 tabs , all of them are empty except for one which shows a hierarchy (built using <ul> and <li> tags).
Scenario,
Issue
Once the AJAX response is added to the DOM, the GriD is no longer accessible. None of the rows are selectable anymore, the below line returns null
var grid = $('#MasterGrid').data("kendoGrid");
Any help appreciated.
-Harris
Hi there,
I am using the MultiSelectFor control bound to a model property in a MVC 5 razor webpage. I am able to select multiple items and create data in our backend system - however, I am running into a few problems when editing this data.
Model property:
[DataType(
"MultiSelect"
)]
[Required]
public
List<
string
> Teams {
get
;
set
; }
Editor Template:
@model IList<
string
>
@Html.Kendo().MultiSelectFor(m => m)
.DataTextField(
"Text"
)
.DataValueField(
"Value"
)
.Filter(
"contains"
)
.AutoClose(
false
)
.Placeholder(
"Please Select"
)
.ValuePrimitive(
true
)
.Deferred()
.BindTo(selectList)
.ToClientTemplate();
The list it is bound to is an IEnumerable<SelectListItem>
When the screen loads, everything appears fine - the multiselect field is bound to the correct items and displays correctly.
However, if I attempt to remove one of the selected items by clicking on the delete option, I receive a javascript error in kendo.all.min.js:
0x800a138f - JavaScript runtime error: Unable to get property 'top' of undefined or null reference
The multiselect then appears to have lost it's list of values, which will only reappear if I start typing.
Any ideas what could be the issue here? If I expand the list first prior to deleting, I receive no issues when removing a selected item.
Thanks,
Paul.
I am building an application in ASP.NET MVC where I am building different Kendo charts to show realtime data with SignalR. I am trying to let the Hub push data constantly to the chart. But I only manage to let the chart update its data on page load, not realtime.
<script src=
"@Url.Content("
~/Scripts/jquery.signalR-2.2.0.min.js
")"
></script>
<script src=
"@Url.Content("
~/signalr/hubs
")"
></script>
<script>
var
hub,
hubStart;
$(
function
() {
var
hubUrl =
"http://localhost:52373/signalr/hubs"
;
var
connection = $.hubConnection(hubUrl, { useDefaultPath:
false
});
hub = connection.createHubProxy(
"serverHub"
);
$.connection.hub.logging =
true
;
hubStart = connection.start();
});
</script>
@(Html.Kendo().Chart<
Model.ServerState
>()
.Name("server1")
.Title(title => title
.Text("Server 1")
.Color("White")
.Font("25px Arial")
)
.Legend(legend => legend
.Color("Gray")
.Position(ChartLegendPosition.Bottom)
.Font("20px Arial")
)
.ChartArea(chartArea => chartArea
.Background("transparent")
)
.SeriesDefaults(seriesDefaults =>
seriesDefaults.Line().Style(ChartLineStyle.Smooth)
)
.Series(series =>
{
series.Line(model => model.Performance.Memory).Name("Memory");
series.Line(model => model.Performance.Processor).Name("Processor");
})
.CategoryAxis(axis => axis
.Title(categoryTitle => categoryTitle
.Text("Time")
.Font("25px Arial"))
.Color("Gray")
.Labels(labels => labels
.Font("20px Arial"))
.MajorGridLines(lines => lines.Visible(false))
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}%"))
.Line(line => line.Visible(false))
.AxisCrossingValue(-10)
.Color("Gray")
.Labels(labels => labels
.Font("20px Arial"))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}%")
)
.DataSource(source => source
.SignalR()
.AutoSync(true)
.Transport(transport => transport
.Promise("hubStart")
.Hub("hub")
.Client(c => c
.Read("read"))
.Server(server => server
.Read("read")
))
.Schema(schema => schema
.Model(model =>
{
model.Id("Id");
model.Field("Id", typeof(int)).Editable(false);
model.Field("Memory", typeof(float));
model.Field("Processor", typeof(float));
}
)
))
)
//Best case:
public
ServerStateEvent Read()
{
//Inside thread which pushes an message containing the object to kendo chart
Clients.All.sendMessage(msg);
}
//Current case, this method has to be called by kendo chart to update its data realtime
public
ServerStateEvent Read()
{
//this method gets data and returns it to kendo chart
return
msg;
}
What I want is the "best case" where the Hub pushes data with the sendMessage function to kendo. This does not seems possible?
The current case works but only one time, the autoSync in kendo does not help.