Showing tooltip for the frozen row in Kendo Grid - kendo-ui

I have a kendo grid with a one frozen row on the top. I wanted to show a tool tip when user hover mouse over the grid row. I was able to show tooltip for all the rows except for the top frozen row. The top frozen row still shows data from the second row.
$(document).ready(function () {
$("#grid").kendoGrid({
autoBind: false,
height: 300,
columns: [{ field: "Source", title: "Source" },
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" }],
dataSource: {
data: [
{ Source: "Master", FirstName: "Foo", LastName: "Bar" },
{ Source: "2", FirstName: "FirstName 2", LastName: "Last Name 2" },
{ Source: "3", FirstName: "FirstName 3", LastName: "Last Name 3" },
{ Source: "4", FirstName: "FirstName 4", LastName: "Last Name 4" },
{ Source: "5", FirstName: "FirstName 5", LastName: "Last Name 5" },
{ Source: "6", FirstName: "FirstName 6", LastName: "Last Name 6" },
{ Source: "7", FirstName: "FirstName 7", LastName: "Last Name 7" },
{ Source: "8", FirstName: "FirstName 8", LastName: "Last Name 8" },
{ Source: "9", FirstName: "FirstName 9", LastName: "Last Name 9" },
{ Source: "10", FirstName: "FirstName 10", LastName: "Last Name 10" },
{ Source: "11", FirstName: "FirstName 11", LastName: "Last Name 11" },
{ Source: "12", FirstName: "FirstName 12", LastName: "Last Name 12" }
]
}
});
var kGrid = $("#grid").data("kendoGrid");
kGrid.bind("dataBound", function (e) {
console.log("dataBound");
var frozenRow;
var items = e.sender.items();
items.each(function () {
var row = $(this);
var dataItem = e.sender.dataItem(row);
if (dataItem.Source == "Master") {
frozenRow = row;
}
})
if (frozenRow) {
var cloned = frozenRow.clone();
cloned.addClass("im-frozen-row");
var thead = kGrid.element.find(".k-grid-header table thead");
thead.append(cloned);
frozenRow.hide();
}
});
kGrid.dataSource.fetch();
$("#grid").kendoTooltip({
filter: ".k-master-row", //this filter selects the second column's cells and the second column header
position: "top",
width: 250,
content: function (e) {
// If the element is the header, return the text of the cell.
if (e.target.is("th")) {
return e.target.text();
}
var dataItem = $("#grid").data("kendoGrid").dataItem(e.target);
return "Source: " + dataItem.Source + "<br/>" + dataItem.FirstName + "," + dataItem.LastName;
}
}).data("kendoTooltip");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.mobile.all.min.css">
<script src="https://kendo.cdn.telerik.com/2022.1.412/js/kendo.all.min.js"></script></head>
<div id="grid"></div>

Try this, I am using your custom class that you are adding to the row that you clone into header section "im-frozen-row" to identify your frozen row when you are adding tooltips.
Your if condition is not able to identify your row since it is not a "th" type element. And since you are already having a class that you add in your clone, it is easier to find the element you're looking for.
$("#grid").kendoTooltip({
filter: ".k-master-row", //this filter selects the second column's cells and the second column header
position: "top",
width: 250,
content: function (e) {
if(e.target.hasClass("im-frozen-row")) { //Note this will allow to identify your frozen row
let arr = e.target.text().match(/[A-Z][a-z]+/g); // Here your returned response is for your data here "MasterFooBar", because this is hardcoded data I can break the words into 3 words, but if you'd like to have exact same tooltips as other rows with some other type of data it will not work.
let str = `Source: ${arr[0]}, First Name: ${arr[1]}, Last Name: ${arr[2]}`; // I am concatenating string to show exactly the type of tooltip other rows have.
return str;
}
var dataItem = $("#grid").data("kendoGrid").dataItem(e.target);
return "Source: " + dataItem.Source + "<br/>" + dataItem.FirstName + "," + dataItem.LastName;
}
}).data("kendoTooltip");
Please note that you can also print your tooltip as is what is returned from "e.target.text()".

Related

How to override editing row and call custom edit in jsgrid

Tried this How to customize edit event in JsGrid as below. But doesnt seem to work
$("#jsgrd").jsGrid({
data: ds,
fields: [{
type: "control",
editItem: editrow(item)
}, ]
});
function editrow(item) {
var $row = this.rowByItem(item);
if ($row.length) {
console.log('$row: ' + JSON.stringify($row)); // I modify this
this._editRow($row);
}
}
The error I get now is "item" not defined.
What I m looking for is, when user clicks edit, I want to get the rowid stored in a hidden col and use it to fetch more data from server and populate outside jsgrid. And avoid changing the row to edit mode
You are not using the documented way. You should use editTemplate.
A simple working example is:
$(document).ready(function() {
$("#grid").jsGrid({
width: "100%",
editing: true,
autoload: true,
data: [ { id:1, name:"Tom"}, {id:2, name:"Dick"}],
fields: [
{ name: "id", type: "text", title: "Id"},
{ name: "name", type: "text", title: "Name",
editTemplate: function(item) {
return "<input type='checkbox'>" + item;
}},
{ type: "control"}
]
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
<div id="grid">
Test
</div>
For the purpose of illustration, I turn the edit of the name field from the standard text box into a check box.
You could use itemTemplate to get the required result.
itemTemplate is a function to create cell content. It should return markup as string, DomNode or jQueryElement. The function signature is function(value, item), where value is a value of column property of data item, and item is a row data item.
Inside of itemTemplate you can customise your dom element based on your requirement.
Run Demo
$("#jsGrid").jsGrid({
width: "100%",
height: "auto",
paging: false,
//for loadData method Need to set auto load true
autoload: true,
noDataContent: "Directory is empty",
controller: {
loadData: function(filter) {
var data = [{
id: 1,
nickname: "Test",
email: "t#gmail.com"
}, {
id: 2,
nickname: "Test 1",
email: "t1#gmail.com"
}, {
id: 3,
nickname: "Test 2",
email: "t2#gmail.com"
}, {
id: 4,
nickname: "Test 3",
email: "t3#gmail.com"
}];
return data;
}
},
fields: [{
name: "nickname",
type: "text",
width: 80,
title: "Name"
}, {
name: "email",
type: "text",
width: 100,
title: "Email Address",
readOnly: false
}, {
type: "control",
itemTemplate: function(value, item) {
var editDeleteBtn = $('<input class="jsgrid-button jsgrid-edit-button" type="button" title="Edit"><input class="jsgrid-button jsgrid-delete-button" type="button" title="Delete">')
.on('click', function (e) {
console.clear();
if (e.target.title == 'Edit') {
//Based on button click you can make your customization
console.log(item); //You can access all data based on item clicked
e.stopPropagation();
} else {
//Based on button click you can make your customization
console.log('Delete')
}
});
return editDeleteBtn; //
},
}]
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
<div id="jsGrid"></div>

How to access to data row in kendo ui grid column command template?

I want to access to data row in kendo ui grid column command template ,but not found solution to resolve this request.
<script>
$("#grid").kendoGrid({
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>",
imageClass: "fa fa-comment-o",
click: note_Clicked
}
]
});
</script>
i want to access to ID value from data of row in column command template as : #: rowData.ID #
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>"
How to resolve this solution?
I don't think you can do it the way you are. I think you don't have access to the row data in that manner.
If you replace your rowData.ID with a function call instead, the function only executes twice, not once for every rendered row, which means the template is only "executed" during grid initialization.
I found this Telerik forum post that talks about this: http://www.telerik.com/forums/accessing-row-data-in-a-command
Where it is suggested that you use the Grid's dataBound event to change the text on the buttons and they provided a link to a demo Dojo.
Here is a link to a demo where I took the dojo from the forum post and slightly modified the dataBound handler to use the Id from the dataItem to dynamically changed the text on the button.
http://dojo.telerik.com/#Stephen/oVuCo
I'm not sure how else to do it.
I had the same problem. The solution I came to is below.
Instead of column command you can use simple column template where the data are accessible. Like that:
{
title: "Status", width: "140px",
template: (item) => {
if (item.Status == 'Outstanding') {
return "<a class='ignore-outstanding' >Outstanding</a>";
} else
return item.Status;
}
},
And add your click handler in dataBound handler like that:
dataBound: () => {
var grid = $(gridSelector).data("kendoGrid");
$(gridSelector + cellSelector).click((e) => {
e.preventDefault();
var dataItem = grid.dataItem($(e.currentTarget).closest("tr"));
alert(dataItem.YourField);
});
},
try this one
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
id: "Id",
fields:{
Id: {type: "number"},
firstname: { type: "string"},
lastname: { type: "string"},
cellphone: { type: "string"},
deskphone: { type: "string"},
emailaddress: { type: "string"}
}
}
}
},
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template: "<a class='tds-grid-button k-button k-grid-#=name#' title='#=name#'>
#=Id# <i class='fa fa-comment-o'></i></a>"
}
]
});
</script>
Note-
in place of #=Id# put the primary field you want to set in kendo grid.
i think you have model in kendo grid datasource.
Tanks,
i find my solution to resolve it.
you can use dataBound event of kendo ui grid as follows:
$("#grid").kendoGrid({
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>",
imageClass: "fa fa-comment-o",
click: note_Clicked
}
],
dataBound: function () {
var grid = this;
var model;
grid.tbody.find("tr[role='row']").each(function () {
rowData = grid.dataItem(this);
rowData.ID
rowData.Name
//and more and more
}
}
});

Kendo Treeview checked Get parent node on checking child nodes

enter image description hereIĀ“m trying to use a treeview with checkboxes for definition User Rights. (2 actions - enabled/disabled right)
How can I to get value (id) from parent node ?
Kendo tree view
This example will return the parent id for the selected node.
treeView.select().parentNode().id;
If you need to find the parent for a specific node, you must specify a selector in the select() function: treeView.select($("search criteria"))
If you want to loop in the parent, you can do this
var parentNode = treeView.select().parentNode();
while (parentNode) {
//Add your parent logic here
//...
parentNode = parent.parentNode();
}
Please try with the below code snippet.
<!DOCTYPE html>
<html>
<head>
<title>Jayesh Goyani</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/kendo.all.min.js"></script>
</head>
<body>
<div id="treeview"></div>
<p id="result">No nodes checked.</p>
<script>
$(document).ready(function () {
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true
},
check: onCheck,
dataSource: [{
id: 1, text: "1", expanded: true, items: [
{
id: 2, text: "2", expanded: true, items: [
{ id: 3, text: "3" },
{ id: 4, text: "4" },
{ id: 5, text: "5" }
]
},
{
id: 6, text: "6", expanded: true, items: [
{ id: 7, text: "7" },
{ id: 8, text: "8" },
]
},
{
id: 9, text: "9", expanded: true, items: [
{ id: 10, text: "10" },
{ id: 11, text: "11" },
{ id: 12, text: "12", expanded: true, items: [{ id: 13, text: "13", expanded: true, items: [{ id: 14, text: "14" }, { id: 15, text: "15" }] }] }
]
}
]
}]
});
});
// function that gathers IDs of checked nodes
function checkedNodeIds(nodes, checkedNodes) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].checked) {
getParentIds(nodes[i], checkedNodes);
checkedNodes.push(nodes[i].id);
}
if (nodes[i].hasChildren) {
checkedNodeIds(nodes[i].children.view(), checkedNodes);
}
}
}
function getParentIds(node, checkedNodes) {
if (node.parent() && node.parent().parent() && checkedNodes.indexOf(node.parent().parent().id) == -1) {
getParentIds(node.parent().parent(), checkedNodes);
checkedNodes.push(node.parent().parent().id);
}
}
// show checked node IDs on datasource change
function onCheck() {
var checkedNodes = [],
treeView = $("#treeview").data("kendoTreeView"),
message;
checkedNodeIds(treeView.dataSource.view(), checkedNodes);
if (checkedNodes.length > 0) {
message = "IDs of checked nodes: " + checkedNodes.join(",");
} else {
message = "No nodes checked.";
}
$("#result").html(message);
}
</script>
</body>
</html>
Let me know if any concern.

Kendo UI showColumn multi-column

I'm using showColumn and hideColumn to show and hide columns in a Kendo UI grid.
But, now with the addition of multi-column headers, I can only hide and show the top level headers.
Here's an example of the js:
$('#data-plan').click(function () {
$('#data-plan').find('i').toggleClass('show hidden');
var grid = $("#lpdatagrid").data("kendoGrid");
var col = 0;
if (grid.columns[col].hidden) {
grid.showColumn(+col);
} else {
grid.hideColumn(+col);
}
});
Using "0" shows/hides the first level column of the multi-column header. What are the column "numbers" for the second level headers that I can call with showColumn and hideColumn?
I apologize for poor code. I'm not a developer.
You might use the name of the field in the column that you want to show / hide. Assuming that you have a Grid that has a Country column, grouped under Location that is under Contact Info, something like:
columns: [
{
field: "CompanyName",
title: "Company Name"
},
{
title: "Contact Info",
columns: [
{
field: "ContactTitle",
title: "Contact Title"
},
{
field: "ContactName",
title: "Contact Name"
},
{
title: "Location",
columns: [
{ field: "Country" },
{ field: "City" }
]
},
{
field: "Phone",
title: "Phone"
}
]
}
]
Then you can use:
var grid = $("#grid").data("kendoGrid");
// Get the "Country" column that is
var col = grid.columns[1].columns[2].columns[0];
// Check if it is visible or hidden
if (col.hidden) {
grid.showColumn(col.field); // or directly grid.showColumn("Country");
} else {
grid.hideColumn(col.field); // or directly grid.hideColumn("Country");
}
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
},
pageSize: 20
},
height: 300,
pageable: true,
columns: [
{
field: "CompanyName",
title: "Company Name"
},
{
title: "Contact Info",
columns: [
{
field: "ContactTitle",
title: "Contact Title"
},
{
field: "ContactName",
title: "Contact Name"
},
{
title: "Location",
columns: [
{ field: "Country" },
{ field: "City" }
]
},
{
field: "Phone",
title: "Phone"
}
]
}
]
});
$("#country").on("click", function() {
var grid = $("#grid").data("kendoGrid");
var col = grid.columns[1].columns[2].columns[0];
if (col.hidden) {
grid.showColumn(col.field);
} else {
grid.hideColumn(col.field);
}
});
});
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic.com/2014.3.1119/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script>
<button id="country" class="k-button">Toggle Country</button>
<div id="grid"></div>

KendoGrid doesn't work in kendoTabStrip

I'm using kendoTabStrip as is shown on KendoUI Page. In my case in each div I have rendered partial view. In a few of my partial views I have additionaly kendoGrid.
Problem
When I reload page in any tab and go to tab which contain kendoGrid then it do not work correctly. For example: I'm on tab#0 and go for tab#3 which contain kendoGrid with pagination, then pagination is not display. But when I reload it then pagination works fine.
What can I do to my Grids works inside TabStrip?
Any help would be appreciated.
UPDATE
My implementation of tabstrip
$("#tabStrip").kendoTabStrip({
animation: { open: { effects: false} },
select: function (e) {
document.location.hash = 'tab-' + $(e.item).index();
}
});
var tabStrip = $('#tabStrip').data('kendoTabStrip');
var tabId = 0;
var scheduledId = 0;
if (document.location.hash.match(/tab-/) == 'tab-') {
tabId = document.location.hash.substr(5);
}
if (document.location.hash.match(/scheduled-/) == 'scheduled-') {
tabId = 1;
scheduledId = document.location.hash.substr(11);
editSchedule('/admin/Course/Scheduled/' + scheduledId + '/Edit/' );
}
tabStrip.select(tabStrip.tabGroup.children('li').eq(tabId));
So I need it to make some rewrites from controller.
To fix this problem we must change :
$("#tabStrip").kendoTabStrip({
animation: { open: { effects: false} },
select: function (e) {
document.location.hash = 'tab-' + $(e.item).index();
}
});
for:
$("#tabStrip").kendoTabStrip({
animation: { open: { effects: false} },
select: function (e) {
document.location.hash = 'tab-' + $(e.item).index();
},
activate: function(e) {
$(e.contentElement).find('.k-state-active [data-role="grid"]').each(function() {
$(this).data("kendoGrid").refresh();
});
}
});
Event activate is 'Triggered just after a tab is being made visible, but before the end of the animation'. So we must refresh our grids then becouse js counts widths of hidden elements wrong.
I put together an example of Grids working inside of a TabStrip: http://jsfiddle.net/dpeaep/SJ85S/. Maybe, I am missing part of what you are asking in your question. If so, you can modify the jsfiddle to clarify what the problem is.
HTML
<div id="tabstrip">
<ul>
<li>Grid 1</li>
<li>Grid 2</li>
<li>Grid 3</li>
</ul>
<div><div id="grid1"></div></div>
<div><div id="grid2"></div></div>
<div><div id="grid3"></div></div>
</div>
Javascript
var tabstrip = $("#tabstrip").kendoTabStrip().data("kendoTabStrip");
tabstrip.select(0);
$("#grid1").kendoGrid({
columns: [
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" }
],
dataSource: {
data: [
{ FirstName: "Joe", LastName: "Smith" },
{ FirstName: "Jane", LastName: "Smith" }
]
}
});
$("#grid2").kendoGrid({
columns: [
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" }
],
dataSource: {
data: [
{ FirstName: "Betty", LastName: "Lakna" },
{ FirstName: "Fumitaka", LastName: "Yamamoto" },
{ FirstName: "Fred", LastName: "Stevenson" }
]
}
});
$("#grid3").kendoGrid({
columns: [
{ field: "Title", title: "Title" },
{ field: "Year", title: "Year" }
],
dataSource: {
data: [
{ Title: "Lost in Domtar", Year: "2012" },
{ Title: "Evergreen", Year: "2012" },
{ Title: "Fields of Yellow", Year: "2010" },
{ Title: "Where the Whistle Blows", Year: "2008" }
]
}
});

Resources