Angular Kendo tabStrip - dynamic content and auto-select first tab - kendo-ui

Using the Kendo UI tabStrip widget, I'd like to do two things:
1) auto-select the first tab, as it does not show the tab content right away.
2) Swap out the contentUrl of the first tab, under a specific condition of course.
Funny thing is, when I use the k-content-urls directive on my Html, the first tabs loads up the content right away.
ex/
<div kendo-tab-strip k-content-urls="['myTemplate.html', 'myTemplate2.html']">
However, I don't want to do it this way. I prefer the approach below, as in k-options="settings.tabOptions"
Here are the tabOptions in my controller code, and the HTML markup below it:
settings.tabOptions = {
animation: { open: { effects: "fadeIn" } },
select: function (e) {
console.log("Selected: " + e.item.innerText);
// NOT WORKING..
e.sender.dataSource.options.data[0].contentUrl = "../myNewTemplate.html"
},
change: function (e) {
console.log("Changed: ");
},
activate: function (e) {
console.log("Activated: " + e.item.innerText);
},
show: function (e) {
console.log("Shown: " + e.item.innerText);
},
contentLoad: function (e) {
console.log("Content loaded in " + e.item.innerText);
},
dataTextField: "title",
dataContentUrlField: "contentUrl",
dataSource: [{
title: "Formatting",
contentUrl: '../app/shared/include/grid-config/gad-config-grid-prop.html'
},
{
title: "Dimensions",
contentUrl: '../app/shared/include/grid-config/gad-config-grid-dimen.html'
},
{
title: "Risk Measures",
contentUrl: '../app/shared/include/grid-config/gad-config-grid-riskmeasures.html'
}],
error: function (e) {
console.log("Loading failed with " + e.xhr.statusText + " " + e.xhr.status);
}
};
<div id="Gadgettabs" kendo-tab-strip="tabstrip" k-options="settings.tabOptions">
<ul>
<li class="k-state-active">Formatting</li>
<li>Dimensions</li>
<li>Risk Measures</li>
</ul>
</div>
Again, I need to immediately show the first tab's content; and also figure out how to dynamically change out the content of the first tab.
Thanks in advance...
Bob
**** UPDATE ****
I'm trying to dynamically change the contentUrl in the select: event above but it's not working.

Final resolution:
note: if you not using "controller as" syntax in your ng-controller directive (as I am), then just replace my "settings." object with "$scope." in the controller code. And of course in the html, just remove "settings." .
// KENDO TABSTRIP
settings.urls = ['../app/shared/include/grid-config/gad-config-grid-prop.html', '../app/shared/include/grid-config/gad-config-grid-dimen.html', '../app/shared/include/grid-config/gad-config-grid-riskmeasures.html'];
if ($scope.widget.gadgetType == "chart") {
settings.urls[0] = '../app/shared/include/barchart-config/gad-config-barchart-prop.html';
};
settings.tabOptions = {
//animation: { open: { effects: "fadeIn" } },
select: function (e) {
console.log("Selected: " + e.item.innerText);
},
change: function (e) {
console.log("Changed: ");
},
activate: function (e) {
console.log("Activated: " + e.item.innerText);
},
show: function (e) {
console.log("Shown: " + e.item.innerText);
},
contentLoad: function (e) {
console.log("Content loaded in " + e.item.innerText);
},
error: function (e) {
console.log("Loading failed with " + e.xhr.statusText + " " + e.xhr.status);
}
};
<div id="Gadgettabs" kendo-tab-strip="settings.tabStrip"
k-rebind="settings.urls"
k-content-urls="settings.urls"
k-options="settings.tabOptions" >
<ul>
<li class="k-state-active">TAB1</li>
<li>TAB2</li>
<li>TAB3</li>
</ul>
</div>

Related

NVDA reads the first letter of the word, then the word from the autocomplete dropdown list

I am working on .NET MVC project and I have problem with NVDA and JAWS reader on the dropdown list. It is the dropdown autocomplete list, and when I am navigating with the keyboard, it was reading double values from the dropdown list.
Then I have added aria-hidden="true", and now it is reading the first alphabet of the value, then the value. For example, this dropdown list:
car
apple
watch
It is reading this:
c
car
a
apple
w
watch
What should I do to read only values?
Code from cshtml:
<input id="client" aria-hidden="true" type="text" class="form-control" data-html="true" placeholder="Enter #Model.ClientTitle">
Code from JS:
$('#client').autocomplete({
source: function (request, response) {
response($.map(clients, function (item, key) {
return {
label: item.Name + " (" + item.ClientId + ")",
value: item.Name + " (" + item.ClientId + ")",
}
}
}));
},
select: function (event, ui) {
event.preventDefault();
if (ui.item.value === "") {
$('#client').val(null);
return false;
}
$('#client').val(ui.item.label);
},
response: function (event, ui) {
if (!ui.content.length) {
var noResult = { value: "", label: "No matches found." };
ui.content.push(noResult);
}
},
minLength: 3,
delay: 500
});

How to put an if condition under columns in kendo grid

Can we add a if Condition inside the column while describing the columns of the grid? Whats wrong in this code
I want to display one button in the grid under a column ,if length of the text exceeds more than 40char.
I am trying to put an if condition if the content/data is less than 40 char then display the content else display a button , On click of button open a pop-up to display the complete content inside that pop-up?
How we can put the command conditionally to display the button?
Here is my code
columns: [{
field: "id",
title: "ID",
width: "100px"
}, // fields in the grid
{
field: "name",
title: "Name",
width: "100px"
}, {
field: "remarks",
title: "Remarks",
width: "160px", // under this column button will be displayed in each
var length = 40;
if (data.remarks.length > length) { //here this condition seems to be wrong, is there any other way to display the button for this condition
command: {
name: "remarks",
text: "Remarks",
click: function (e) {
var tr = $(e.target).closest("tr");
var data = this.dataItem(tr);
var win = $('#remarksWindow');
win.html(data.remarks);
if (!win.data('kendoWindow')) {
win.kendoWindow({
width: '600px',
height: '200px',
title: 'Remarks',
actions: ['Close']
});
}
win.parent().css({
top: e.pageY - 50,
left: e.clientX - 640,
width: '600px',
height: '200px'
});
win.data('kendoWindow').open(); // open the pop-up which contains the data
return false;
}
}
}
}
},
First of all, you have a syntax error in JavaScript. Note that you can't put statements or declarations between the properties of an object:
var obj = {
a: 1,
if (true) {
b: 2;
}
}
Or
var obj = {
a: 1,
var b = 1;
}
The examples above doesn't works. So in your column property you have to use a template property:
{
field: "remarks",
title: "Remarks",
width: "160px",
template: "" // <- here goes your logic
}
So a simple template can be set as a string containing html with JavaScript logic, e.g.:
# if (remarks.length > 40) { # <input type='button' class='btn-remarks' /> # } #
Yes, you will have to set the button html by yourself. There is no way to add a condition to a command button(and that is a shame, actually).
You can check how template works here.
Then your column item should be:
{
field: "remarks",
title: "Remarks",
width: "160px",
template: "# if (remarks.length > 40) { # <input type='button' class='remarks' /> # } #"
}
Then you have to set the event for all your buttons(probably in the dataBound event):
$("#yourGrid").on("click", ".btn-remarks", function()
{
// all your click logic here
});
Give it a try and tell me what happens.
Hopefully this dojo is what you are looking for: http://dojo.telerik.com/ETora
(I have used one of Telerik's grid demos and modified to show you the principles)
The functionality you are looking for can be achieved by two means:
1) Apply a client Template to the column
2) Add a databound event that then hooks up the buttons
columns:[ {
field: "CompanyName",
title: "Company Name",
template: "#= displayTextorButton(data.CompanyName) #"
}]
function displayTextorButton(data){
var retString = '';
console.log(data);
if(data !== null && data !== undefined)
{
if(data.length > 20)
{
retString = ' <button type="button" class="btn btn-xs btn-primary"' +
'data-toggle="popover" data-placement="auto right" data-container="body" ' +
'data-content="' + kendo.htmlEncode(data) + '"' +
'data-title="Running Log Information" data-trigger="click" data-role-me="content-popover" > <span class="glyphicons glyphicons-pencil"></span> View</button>';
}
else
{
retString = '<span>' + data + '</span>';
}
}else
{
retString = '<span> - </span>';
}
return retString;
}
so the first bit I have done is added a template to the Company Name column that checks if the name is more than 20 characters if it is then it will display a button if it isn't then it will display the text as normal.
function(e){
$('button[data-role-me="content-popover"]').popover({ trigger: "focus", html: true });
}
I then hook up a databound event to the grid to then attach the event features to the "pop up" in my sample
Also note I have hooked in the bootstrap features just to make things a little easier for the demo. So this is using their popover feature. You could modify this code to work with your window.
Any issues let me know.
This is the kendo grid code
{ field: "marks", title: "marks",width: "160px",
template: function(dataItem) {
var marks = dataItem.marks;
var retString = '';
if(marks !== null && marks !== undefined)
{
if(marks.length > 40)
{
marks1 = marks.substring(0, 40)+'...';
retString1 ='<span>'+ marks1 +'</span>';
retString = retString1 + ' <button id="marksButton" type="button"' +
'data-toggle="popover" data-placement="auto right" data-container="body" ' +
'data-content="' + kendo.htmlEncode(addlRemarks) + '"' +
'data-title="marks" data-trigger="click" data-role-me="content-popover" > marks</button>';
}
else
{
retString = '<span>' + marks + '</span>';
}
}else
{
retString = '<span> - </span>';
}
return retString;
}
And its being called from a HTMl
<div class="panel-body" ng-show="accOpen[$index]">
<!-- Marks TABLE -->
<div marks-table=""
accordion-flag="accOpen[$index]"
name="name"
id="id"
>
</div>
</div>

Kendo UI : Autocomplete Template Header

I'm new to Kendo UI. I can't figure out why my autocomplete is not showing the header template.The row template is working fine. I looked at the example and I'm not sure what I'm doing differently
Here is my JavaScript code:
<script>
$(document).ready(function () {
$("#drug_name").kendoAutoComplete({
dataTextField: "name",
change: function (e) {
if ($("#drug_name").val() == "") {
$("#dose").val("");
$("#unit").val("");
$("#route").val("");
}
},
select: function (e) {
var dataItem = this.dataItem(e.item.index());
$("#dose").val(dataItem.dose);
$("#unit").val(dataItem.unit);
$("#route").val(dataItem.route);
//output selected dataItem
console.log(kendo.stringify(dataItem));
},
headerTemplate: '<div class="dropdown-header"><span class="k-widget k-header">Name</span><span class="k-widget k-header">Route</span><span class="k-widget k-header">Dose</span><span class="k-widget k-header">Unit</span></div>',
template: '<span class="k-state-default">#:data.name#</span><span class="k-state-default">#:data.route#</span><span class="k-state-default">#:data.dose#</span><span class="k-state-default">#:data.unit#</span>',
filter: "contains",
minLength: 3,
dataSource: {
serverFiltering: true,
transport: {
read: { url: "/Medication/Load", dataType: "json" },
parameterMap: function (data, action) {
if (action === "read") {
return {
medicationName: data.filter.filters[0].value
};
} else {
return data;
}
}
}
},
height: 370
});
});
Please try to write like this:
headerTemplate: '<div class="dropdown-header">' + '<span class="k-widget k-header">Name</span>' + '<span class="k-widget k-header">Route</span>' + '<span class="k-widget k-header">Dose</span>' + <span class="k-widget k-header">Unit</span>' + '</div>',

How do I configure a Kendo UI grid to use a DropDownList to edit a cell?

I'm having trouble configuring a `Kendo UI' grid to use a DropDownList as an editor. I have a JS Bin example to reproduce my behavior. The goal is to populate the BinNumber, PartNumber and StockNumber fields once a selection is made from the dropdown. Currently I can't even get the DropDown to bind to the recordset properly. If I make a selection and move to another field, I get [object Object] in the BinNumber field. If I go back in and make another selection, the BinNumber then sticks. I have read the documentation thoroughly but I am still thoroughly confused by it.
For the [object object] mess have a look at this post, there is an attribute introduced back in late 2013 dealing with this issue data-value-primitive="true". In the past I just used to re-map the selection back to ds manually, but the attribute does it all for you, I tested in you jsBin and works fine.
binDropdownEditor: function (container, options) {
$('<input data-text-field="BinNumber" data-value-field="BinNumber" data-value-primitive="true" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: viewModel.binDropDownDataSource
});
}
On change binding (please paste into your JSBin javascript tab):
var bins =["BinNumber:12121"];
var gridDS = new kendo.data.DataSource({
transport: {
read: function (e) {
e.success(bins);
}
},
schema: {
model: {
id:"Row",
fields: {
Row:{type:"string"},
BinNumber: {type:"string"},
PartNumber: {type:"string"},
StockNumber:{type:"string"}
}
}
},
pageSize: 50
});
var binDropDownDataSource = [
{ BinNumber: "12345",PartNumber:"P-2929",StockNumber:"S-06565" },
{ BinNumber: "23456",PartNumber:"P-2323",StockNumber:"S-956565" },
{ BinNumber: "34567",PartNumber:"P-4344",StockNumber:"S-67676" } ];
function appendEditor (container, options) {
$('<input data-text-field="BinNumber" data-value-primitive="true" data-value-field="BinNumber" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: binDropDownDataSource,
change:function(e){
var ddldataitem = this.dataItem();
var griditem = gridDS.at(0); // you might need to tweak this line
griditem.set("PartNumber",ddldataitem.PartNumber);
griditem.set("StockNumber",ddldataitem.StockNumber);
}
});
}
var grid= $("#bins").kendoGrid({
dataSource: gridDS,
scrollable: false,
autoBind:false,
batch:true,
editable : true,
navigatable: true,
toolbar: [ {name: 'custom-create', text: "Add New Line Item"}],
columns: [ {"field":"Row", title: "Row", width: "20px"},
{"field": "BinNumber","title":"Bin", editor: appendEditor},
{"field": "PartNumber", title: "Part ", width: "200px",editable: false },
{"field": "StockNumber", title: "Stock ", width: "200px",editable: false }
]
}).data("kendoGrid");
$(".k-grid-custom-create").on("click", function (e) {
gridDS.add({ Row:"1"});
});
The observable you had plugged in is not really necessary the underling data source is already observable, I have removed it. Please consider improving following line the index won't be always 0 var griditem = gridDS.at(0);
Here's how my DropDown is setup. This is a boolean field, so you will have to adjust it accordingly to your field
columns.Bound(m => m.IsInForecast).Title("Is Forecasted").ClientTemplate(
"# if (IsInForecast == true) { #" +
"<select id='#= OrderId #' onchange=save('#= OrderId #'); style='Width: 80px; color: 'navy' > " +
"<option id='yes' selected value='1'>Yes</option>" +
"<option id='no' value='0'>No</option>" +
"</select>" +
"# } else { #" +
"<select id='#= OrderId #' onchange=save('#= OrderId #'); style='Width: 80px; color: 'navy' > " +
"<option id='yes' value='1'>Yes</option>" +
"<option id='no' selected value='0'>No</option>" +
"# } #"
);

Event Changes do not Post with Fullcalendar.js and ASP.Net WebApi

I'm trying to use the Fullcalendar with a MVC WebApi Application. Data gets loaded successfully, but changes do not hit a Post to the Server.
I am using the latest Fullcalendar - Beta.
This is my Fullcalendar - Init:
$(document).ready(function () {
$('#calendar').fullCalendar({
events: '/api/CalendarData',
eventClick: function (calEvent, jsEvent, view) {
var form = $("<form class='form-inline'><label>Change event name </label></form>");
form.append("<input class='middle' autocomplete=off type=text value='" + calEvent.title + "' /> ");
form.append("<button type='submit' class='btn btn-sm btn-success'><i class='icon-ok'></i> Save</button>");
var div = bootbox.dialog({
message: form,
buttons: {
"delete": {
"label": "<i class='icon-trash'></i> Delete Event",
"className": "btn-sm btn-danger",
"callback": function () {
calendar.fullCalendar('removeEvents', function (ev) {
return (ev._id == calEvent._id);
})
}
},
"close": {
"label": "<i class='icon-remove'></i> Close",
"className": "btn-sm"
}
}
});
form.on('submit', function () {
calEvent.title = form.find("input[type=text]").val();
calendar.fullCalendar('updateEvent', calEvent);
div.modal("hide");
return false;
});
...
});
});
These are my WebApiController Methods:
public IEnumerable<FullCalendarEvent> Get(DateTime start, DateTime end)
{
List<FullCalendarEvent> retList = new List<FullCalendarEvent>()
{
new FullCalendarEvent(){
id = 1,
start = new DateTime(2014,2,22,10,00,00),
end = new DateTime(2014,2,22,12,00,00),
title = "Mein zweiter Termin"
},
new FullCalendarEvent(){
id = 2,
start = new DateTime(2014,2,20,10,00,00),
end = new DateTime(2014,2,20,12,00,00),
title = "Mein erster Termin"
}
};
return retList;
}
// POST api/calendardata
public void Post([FromBody]FullCalendarEvent value)
{
}
The Routingdefaults of the MVC WebApi - Projecttemplates are untouched.
Thank You!
I'm not sure if it is correct this way, but it works for me. I am programming the posts by myself using $.post.
This is the Code now:
eventClick: function (calEvent, jsEvent, view) {
var form = $("<form id='EditEventForm' class='form-inline' method='post' action='api/changes/EditEvent' enctype='application/x-www-form-urlencoded'><label>Change event name </label>");
form.append("<input id='title' name='title' class='middle' autocomplete=off type=text value='" + calEvent.title + "' data-val='true' /> ");
form.append("<input id='id' type='hidden' value='1' name='id' data-val='true'>");
form.append("<button type='submit' class='btn btn-sm btn-success'><i class='icon-ok'></i> Save</button></form>");
var div = bootbox.dialog({
message: form,
buttons: {
"delete": {
"label": "<i class='icon-trash'></i> Delete Event",
"className": "btn-sm btn-danger",
"callback": function () {
calendar.fullCalendar('removeEvents', function (ev) {
return (ev._id == calEvent._id);
})
}
},
"close": {
"label": "<i class='icon-remove'></i> Close",
"className": "btn-sm"
}
}
});
form.on('submit', function () {
var Event = JSON.stringify(calEvent);
Event = $('#EditEventForm').serialize();
$.post('api/CalendarData/EditEvent', Event);
});

Resources