Kendo Tooltip content chnages dynamically depending on the other 2 row data - javascript

I have grid which has around 8 columns, 8th column has the delete button. When the user hovers over the delete button tooltip should appear with some content. Now the content in the tooltip depends on the row value from 6th and 7th column. Consider if the row value of 6th column is 'Yes' and row value of 7th column is "No", tooltip content will be Hello and as the row value of 6th and 7th column changes tooltip content will also change. Below is my code, but i am unable to get that.
function initializeGrid() {
$("#wellboreGrid").kendoGrid({
filterable: true,
resizeable: true,
reorderable: true,
columnMenu: true,
scrollable: false,
dataBound: function (e) {
debugger;
$("#wellboreGrid").find(".k-button").kendoTooltip({
content:e.data.item.ExistingAssn=="Yes" && e.data.item.ExistingGeologic=="NO" ? "Hello" : e.data.item.ExistingAssn=="Yes" && e.data.item.ExistingGeologic=="YES" ? "EXIT":e.data.item.ExistingAssn=="No" && e.data.item.ExistingGeologic=="YES" ? "WHAT" : Error,
width: 100,
height: 60,
position: "bottom",
});
},
columns: [
{ field: "FacilityId", title: "", hidden: true },
{ field: "FacilityName", title: "Shell Name" },
{ field: "shortName", title: "Shell Short Name" },
{ field: "ApiNumber", title: "API Number" },
{ field: "InService", title: "Service Status" },
{ field: "State", title: "State" },
{ field: "ExistingAssn", title: "Existing Association", format: "{0:c}" },
{ field: "ExistingGeologic", title: "Existing Geologic", format: "{0:c}" },
{ field: "LithoStratColoumnId", title: "", hidden: true },
{ field: "GeoIntervalId", title: "", hidden: true },
{ command: [{ click: deleteItem, text: "X" }], title: "Delete" }
]
});
$("#dvshowWellbore").attr("style", "display:inline;float: left;font-weight:bolder;font-style:italic;padding-bottom:10px;padding-left:15px;font-size:15px;");
$("#wellboreGrid").find('.k-grid-header .k-header').css('font-weight', 'bold');
};

Related

Kendo Grid Separate Popup Window Title & Buttons for Create & Edit

I want to change the title of the editable popup window based on whether it is being used to create or edit a grid item (I want the fields to be the same for both of them, though).
I have set the popup window's title in editable
editable: {
mode: "popup",
template: kendo.template($("#popupTemplate").html()),
window: {
title: "Add"
}
}
But I'm not sure how to differentiate between Edit and Add. The Edit button is in the columns:
command: [
{
name: "edit",
text: {
edit: "Edit",
update: "Save",
cancel: "Cancel"
}
}
]
and the Add button in the toolbar:
toolbar: [{name: 'create'}]
Notably, I've tried this to no avail:
toolbar: [
{
name: 'create',
click: function(){
alert("test");
}
},
]
I've also seen e.model.isNew() used under edit, but according to my compiler, this is not a function.
I've looked all over the internet and Telerik and found nothing. Am I missing something?
EDIT: Someone asked for the entirety of my grid code:
var grid = $('#grid').kendoGrid({
//dataSource: this.source,
dataSource: this.testData,
height: 550,
filterable: true,
sortable: true,
pageable: {
pageSize: 30,
buttonCount: 1
},
//toolbar: ["create", "destroy", "search"],
toolbar: [
{name: 'create'},
{name: 'destroy'},
{name: 'search'},
{template: "<input id='category' type='search' style='width: 250px; float: right;'/>"}
],
resizeable: true,
columns: [
{
field: 'Name',
title: 'Name',
filterable: true,
},
{
field: 'MCN',
title: 'P/N',
filterable: false,
},
{
field: 'ID',
title: 'ID',
filterable: true,
},
{
field: 'Type',
title: 'Type',
filterable: true,
},
{
field: 'Subtype',
title: 'Subtype',
filterable: true,
},
{
field: 'Value',
title: 'Value',
filterable: false,
},
{
field: 'Tolerance',
title: 'Tolerance',
filterable: true, //Number/letter combination causes problem?
},
{
command: [
{
name: "edit",
text: {
edit: "Edit",
update: "Save",
cancel: "Cancel"
}
},
{
name: "copy",
text: "Copy",
//click: function
}
],
title: " ", width: "250px"
},
],
editable: {
mode: "popup",
template: kendo.template($("#popupTemplate").html()),
// window: {
// title: "Add"
// }
},
selectable: "multiple, row", // Select multiples by drag or Shift-Click
edit: function(e){
var container = e.container;
var model = e.model;
//console.log(model.get("ID"));
// Changing the size of the container
$(e.container).parent().css({
//width: "1000px",
//height: "500px"
});
//May be able to simplify this with a for loop
// Changing Type input to a dropdown
var input = $('#dropType');
input.kendoDropDownList({
dataTextField: "Type",
dataValueField: "dropType",
dataSource: [{Type: 'One'}, {Type: 'Two'}, {Type: 'Three'}],
}).appendTo(container);
// Changing Subtype input into a dropdown
var input = $('#dropSubtype');
input.kendoDropDownList({
dataTextField: "Subtype",
dataValueField: "dropSubtype",
dataSource: [{Subtype: 'One'}, {Subtype: 'Two'}, {Subtype: 'Three'}],
}).appendTo(container);
}
});
To change the title you should use edit function of the grid like this:
$("#grid").kendoGrid({
dataSource: {...},
height: 550,
toolbar: ["create"],
columns: [
{
field: "",
title: '',
attributes: { style: "text-align:center;" },
headerAttributes: { style: "text-align: center;" }
},
{
command: [
{ name: "edit", text: 'Edit' },
],
title: 'tools',
width: "200px",
attributes: { style: "text-align:center;" },
headerAttributes: { style: "text-align: center;" }
}
],
editable: {
mode: "popup",
template: $("#template").html(),
},
edit: function(e) {
if (e.model.isNew()) {
e.container.kendoWindow("title", "Createee");
} else {
e.container.kendoWindow("title", "Updateee");
}
}
});
And for using the template, see this answer : Kendo UI Grid popup
Edit:
According to kendo : Kendo Forum , isNew
The isNew method returns true or false depending on the id value of that model.
If the id is still set to the default value then it will assume it is a New Model.
So I think your problem is because of your dataSource, and you should fill id before the fields property. like this :
dataSource: {
transport: {
read: {
url: ...
type: "POST", // The request type.
dataType: "json", // The data type of the returned result.
},
create: {...},
update: {...},
destroy: {...}
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false },
BankName: { type: "string", validation: { required: true } },
....
}
}
},
pageSize: 20
},
And here are two Samples: ( Sample 1 , Sample 2 )

Modifying Group Header to include children count Kendo UI Grid

I have a Kendo UI Grid created in javascript. I have a defalut grouping, then the user can select other groupings. Ineed help with a couple things:
1.I would like to make a custom group header so it includes a count of the children rows.
On mouseover of the Group Header I need to change the related marker on a Google Maps instance. (The group contains the lat and long of the client.
function loadGrid(dataItem) {
$("#grid").kendoGrid({
dataSource: {
dataType: "json",
transport: {
read: {
url: serviceUrl",
dataType: "json",
},
},
schema: {
data: "result.results",
},
group: {
field: "siteName", field: "siteName",
},
},
dataBound: onDataBound,
pageSize: 20,
height: 550,
filterable: true,
groupable: true,
sortable: true,
pageable: true,
collapse: true,
columns: [
{
field: "dirId",
title: "Dir Id",
hidden: true
},
{
field: "dirName",
Title: "Dir Name",
hidden: true
},
{
field: "siteId",
title: "Site Id",
hidden: true
},
{
field: "siteName",
title: "Site Name",
//hidden: true
},
{
field: "appTypeRefId",
title: "App Type Ref Id",
hidden: true
},
{
field: "appInstName",
title: "App Instance Name",
},
{
field: "appTypeName",
title: "App Type",
},
{
field: "unitId",
title: "Unit Id",
hidden: true
},
{
field: "unitName",
title: "Unit Name"
},
{
field: "controlSystemId",
title: "Control System Id",
hidden: true
},
{
field: "controlSystemName",
title: "Control System Name"
},
{
field: "longitude",
title: "Longitude",
hidden: true
},
{
field: "latitude",
title: "Latitude",
hidden: true
},
],
})
}
Thanks a ton!
Ron

Kendo grid pagination into custom wrapper

It is my kendo grid and i need to wrap pagination buttons into my custom wrapper, named
var grid = $("#taskTableKendo").kendoGrid({
dataSource: tasksData,
sortable: true,
scrollable: false,
autoBind: false,
pageable: {
refresh: true,
pageSizes: [20, 50, 100]
},
dataBound: tasksDataBound,
columns: [
{ field: "Responsibility_Code", title: " ", width: 30, encoded: false, template: '<span class="responsibility type#=Responsibility_Code#" title="#=Responsibility_Description#"></span>' },
{ field: "TaskRef", title: "Task Ref", encoded: false },
{ field: "Owner_FullName", title: "Owner", width: 80, template: "<span class='usercell'>#=Owner_FullName#</span>" },
{ field: "Property_PropertyRef", title: "Property Ref" },
{ field: "Property_Name", title: "Property Name" },
{ field: "Property_City", title: "City" },
{ field: "Property_Country_Name", title: "Country" },
{ field: "JobType_Name", title: "Job Type",width:700 },
{ field: "TaskStatus", title: "Status" },
{ field: "DueDate", title: "Due" },
{ field: "DateLogged", title: "DateLogged", hidden: true },
{ field: "Comments", hidden: true },
{ field: "Documents", hidden: true },
{
command: [{ text: "Click here to add a comment to this task", className: "addComment", click: addCommentCommand, template: '<div class="dropdown pull-right"><button class="btn btn-link dropdown-toggle text-green-lime" type="button" id="linkDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Actions <span class="caret"></span></button> <ul class="dropdown-menu" aria-labelledby="linkDropdown"><li> <span class="CommentsNumbers"></span></li>' },
{ text: "Click here to add a document to this task", className: "addFile", click: documentCommand, template: '<li><span class="DocumentsNumbers"></span> </li>' },
{ text: "Click here to reallocate this task to a different person", className: "reallocate", data: { field: "Id" }, click: reallocateCommand },
{ text: "Click here to close this task", className: "closeTask", click: completeTaskCommand },
{ text: "Click here to view and edit this task", className: "viewTask", click: editTaskCommand, template: ' </ul> </div>'}
],
title: " ",
width: 185
}
]
});
I just need to change, kendo's go to previous page, go to next page buttons to custom ones created by me in html.
I've found solution, just for changing prev/next buttons you can use
pageable: {
previousNext: true,
messages: {
display: "{0}-{1} of {2} total tasks",
select: "test",
empty: "No tasks to display",
first: "«",
last: "»",
next: "›",
previous: "‹"
},
I've searched all stack overflow, but haven't found correct answer for this.
It is possible to modify the HTML rendering of the Grid pager inside a setTimeout block (no timeout value is required) in the Grid's dataBound event.

Kendo UI Grid Checkbox Column Field Not Defined

I am trying to add a kendo checkbox column. I have done this successfully in another grid. However, when I tried to do the same thing in another grid, I am getting a "IsSimple is undefined" error, where IsSimple is a simple boolean model field.
Model for my kendo data source:
schema: {
data: function (data) { //specify the array that contains the data
console.log("DATA RETURN TEST");
console.log(data);
return data || [];
},
model: {
id: "Id",
fields: {
Id: { editable: false,
nullable: false,
type: "number"
},
DesignatorName: { type: "string" },
TXFreq: { type: "string" },
RXFreq: { type: "string" },
IsSpecial: { type: "bool" },
IsCommand: { type: "bool" },
}
}
Here is my column definition for my kendoGrid.
$("#DesignatorFreqGrid").kendoGrid({
dataSource: DesignatorDS,
columns: [
{ field: "DesignatorName", title: "Frequency", format: "{0:c}", width: "120px" },
{ field: "TXFreq", editor: TXFreqEditor, title: "TX Frequency", format: "{0:c}", width: "120px" },
{ field: "RXFreq", editor: TXFreqEditor, title: "RX Frequency", format: "{0:c}", width: "120px" },
{ field: "IsSpecial", template: '<input type="checkbox" #= IsSpecial ? checked="checked" : "" # disabled="disabled" ></input>', title: "Is Special", format: "{0:c}", width: "120px" },
{ field: "IsCommand", template: '<input type="checkbox" #= IsCommand ? checked="checked" : "" # disabled="disabled" ></input>', title: "Is Command", format: "{0:c}", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }
],
toolbar: ["create"],
editable: "inline",
pageable: true
});
Here is my JSON object:
"other fields........DesignatorName: "11"
EQUIPMENT: ObjectId: 2
IsCommand: true
IsSpecial: true
RXFreq: "55"
TXFreq: "22"
As you can see, IsSpecial is defined. The binding works when I load data into the grid. The checkboxes are indeed checked. But if I try to add a new record with the "Add New Record" button in the grid, I will get the error "Uncaught ReferenceError: IsSpecial is not defined".
If I change the binding to this.IsSpecial, I don't get the error anymore, and can add a new row to my database, but then the binding won't work and the boxes aren't checked when loading the grid,
It seems like it should work, and I do not know where else to look. Any ideas? Thanks.
You need to use boolean, instead of bool.
IsSpecial: { type: "boolean" },
IsCommand: { type: "boolean" }

Kendo Grid Custom Column

I have the following code:
$("#grid").kendoGrid({
dataSource: {
type: "odata",
data: scannedResult.targetList,
pageSize: 20
},
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status"
}, {
field: "comment",
title: "comment"
}]
});
creating a kendo simple grid. for detail here is my plunker.
now the field status can be 1 of 3 values: passed, failed, skipped. I would like that the statuscolumn will show an icon instead of the value. While the code for that is rather simple, i do not know how to make the column a custom column.
Is there a way to make a column a custom column?
You should use a template definition. Something like:
Define the template.
<script id="status-template" type="text/kendo-templ">
# if (data.status === 1) { #
<span>Status1</span>
# } else if (data.status === 2) { #
<span>Status 2</span>
# } else { #
<span>Status 3</span>
# } #
</script>
Reference the template from the column definition
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status",
template: $("#status-template").html()
}, {
field: "comment",
title: "comment"
}]
See it running here: http://jsfiddle.net/OnaBai/5x8wt0f7/
Obviously, the template can emit any HTML code, it might be links, images...
This has already been answered, but I want to show how I'd write this if people are confused when linking to jQuery selector.
// Custom Template that takes in entire Row object
function statusTemplate(dataRow) {
return `<span class="label label-${dataRow.status.toLowerCase()}">${dataRow.status}</span>`;
}
// Column definitions for grid
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status",
template: statusTemplate
}, {
field: "comment",
title: "comment"
}]
http://jsfiddle.net/dentedio/hdokxme9/1/

Categories

Resources