Kendo Heirarchical Grid Alignment Issue - kendo-ui

I have implemented two Kendo Grids, first one is the parent Grid and other is the child Grid.
When I open the Child Grid to view the values for each parent element in the Parent Grid,
the column alignment of both the Grids are mismatched.
Any help on how to solve this ?
Here is the general code :-
// This is the Parent Grid
#(Html.Kendo().Grid<XYZ.Models.ViewModels.ABCMODEL>()
.Name("ParentGrid")
.Columns(columns =>
{
columns.Bound(e => e.A).Title("ABC").Width(30);
columns.Bound(e => e.B).Title("EFG").Width(30).HeaderHtmlAttributes(new { style = "background-color:#996666;" });
columns.Bound(e => e.C).Title("IJK").Width(30).HeaderHtmlAttributes(new { style = "background-color:#996666;" });
columns.Bound(e => e.D).Title("MNO").Width(30).HeaderHtmlAttributes(new { style = "background-color:#996666;" });
columns.Bound(e => e.E).Title("XYZ.").Width(30).HeaderHtmlAttributes(new { style = "background-color:#996666;" });
})
//.Scrollable()
.DetailTemplateId("template")
.HtmlAttributes(new { style = "height:100%; background-color: #fcfedf;" })
.HtmlAttributes(new { #class = "tableMain" })
.DataSource(dataSource => dataSource
.Ajax()
// .PageSize(6)
.Read(read => read.Action("HierarchyBinding_ABC", "Profit"))
)
.Events(events => events.DataBound("dataBound"))
//.ColumnMenu()
// .Scrollable()
//.Sortable()
//.Pageable()
)
//This is the Child Grid
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().Grid<ABC.Models.ViewModels.ABCMODEL>()
.Name("grid_#=CId#")
.Columns(columns =>
{
columns.Bound(e => e.a).Title("123").Width(30);
columns.Bound(e => e.b).Title("456").Format("{0:N3}").Width(30);
columns.Bound(e => e.c).Title("789").Format("{0:N3}").Width(30);
columns.Bound(e => e.d).Title("101").Format("{0:N3}").Width(30);
columns.Bound(e => e.e).Title("112").Format("{0:N3}").Width(30);
})
.DataSource(dataSource => dataSource
.Ajax()
// .PageSize(5)
.Read(read => read.Action("HierarchyBinding_XYZ", "Profit", new { CId = "#=CId#" }))
)
.ToTemplate()
)
</script>
<script>
function dataBound() {
var grid = this;
$(".k-hierarchy-cell").css({ width: 8 });
$(".k-hierarchy-col").css({ width: 8 });
}
</script>
<style>
.k-grid tbody .k-grid .k-grid-header
{
display: none;
}
#ParentGrid .k-grid-header .k-header
{
background-color: #d42e12;
color:White;
font-size:small;
font-style:normal;
border:1px; border-color:Black; border-style:solid; text-align:center;
white-space:nowrap;
}
.k-grid tbody
{
background-color: #fcfedf;
height:100%;
font-size:x-small;
border:none;
border-color: #fcfedf;
white-space:nowrap;
}
#ParentGrid .k-grid td
{
border:none
padding-right: 0em !important;
}
</style>
Hope now the question becomes more clear.
Looking forward to a useful answer.

Had to get a little fancy with some css, but here is a sample of where I had to accomplish this.
http://jsbin.com/uritAno/2/edit
I think the main thing was to override the right padding and border on the grid td's, and set each column to a fixed width, save for one.
.k-grid td
{
border: none;
padding-right: 0em !important;
}

Thanks a lot for your answers and comments.
They helped me a lot in reaching to an answer to my question.
So here is the final solution :
// This is the Parent Grid (No need to do any changes in Parent Grid,it remains as it is
with width attribute in every column)
//This is the Child Grid (All changes are to be done in "Child Grid")
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().Grid<ABC.Models.ViewModels.ABCMODEL>()
.Name("grid_#=CId#")
.Columns(columns =>
{
columns.Bound(e => e.a).Title("123");
columns.Bound(e => e.b).Title("456").Format("{0:N3}").Width(149);
columns.Bound(e => e.c).Title("789").Format("{0:N3}").Width(150);
columns.Bound(e => e.d).Title("101").Format("{0:N3}").Width(137);
columns.Bound(e => e.e).Title("112").Format("{0:N3}").Width(127);
})
.DataSource(dataSource => dataSource
.Ajax()
// .PageSize(5)
.Read(read => read.Action("HierarchyBinding_XYZ", "Profit", new { CId = "#=CId#" }))
)
.ToTemplate()
)
You have to remove the width from the "first column in the child grid i.e. column "a"" and start setting the width from the last column.
Give a width to the last column of child grid such that it gets aligned with the last column of "parent grid" i.e.
Align column "e of child grid" with "E of parent grid" by giving "e" a suitable value.
Once "e" is aligned,it will be fixed,now in the similar way align column "d,b,c" and you will find column "a" aligned with "A in parent grid".
In this way both the grids get aligned.
The values in the width attribute were specific to my screen so i used them.These are not standard values.Try and align the child grid according to your screen,the values might be different.
Hope it helps,thanks a lot and have a great New Year ahead.

I had the same issue with Kendo UI Javascript Grid and inspired by Robin Giltner answer, I resolve by:
1) Using same the width on paired columns which have to be aligned on the right. (Starting from the right)
2) Leaving free width on dynamic width columns. (Starting from the left)
3) Overriding .k-detail-cell class as follows:
.k-detail-cell
{
padding-right: 0em !important;
}
Applying padding-right: 0em !important; to .k-detail-cell we align only the details grid to the right; while applying padding-right: 0em !important; to .k-grid td we align to the right, all the columns of both grids and their content.
(Not nice, because even header and footer are aligned to the right)
Note: Kendo UI version 2014.2.716

Related

How to set the height of CKEditor 5 (Classic Editor)

In CKEditor 4 to change the editor height there was a configuration option: config.height.
How do I change the height of CKEditor 5? (the Classic Editor)
Answering my own question as it might help others.
CKEditor 5 no longer comes with a configuration setting to change its height.
The height can be easily controlled with CSS.
There is one tricky thing though, if you use the Classic Editor:
<div id="editor1"></div>
ClassicEditor
.create( document.querySelector( '#editor1' ) )
.then( editor => {
// console.log( editor );
} )
.catch( error => {
console.error( error );
} );
Then the Classic Editor will hide the original element (with id editor1) and render next to it. That's why changing height of #editor1 via CSS will not work.
The simplified HTML structure, after CKEditor 5 (the Classic Editor) renders, looks as follows:
<!-- This one gets hidden -->
<div id="editor1" style="display:none"></div>
<div class="ck-reset ck-editor..." ...>
<div ...>
<!-- This is the editable element -->
<div class="ck-blurred ck-editor__editable ck-rounded-corners ck-editor__editable_inline" role="textbox" aria-label="Rich Text Editor, main" contenteditable="true">
...
</div>
</div>
</div>
In reality the HTML is much more complex, because the whole CKEditor UI is rendered. However the most important element is the "editing area" (or "editing box") marked with a ck-editor__editable_inline class:
<div class="... ck-editor__editable ck-editor__editable_inline ..."> ... </div>
The "editing area" is the white rectangle where one can enter the text. So to style / change the height of the editing area, it is enough to target the editable element with CSS:
<style>
.ck-editor__editable_inline {
min-height: 400px;
}
</style>
Setting the height via a global stylesheet.
Just add to your common .css file (like style.css):
.ck-editor__editable {
min-height: 500px;
}
In the case of ReactJS.
<CKEditor
editor={ClassicEditor}
data="<p>Hello from CKEditor 5!</p>"
onInit={(editor) => {
// You can store the "editor" and use when it is needed.
// console.log("Editor is ready to use!", editor);
editor.editing.view.change((writer) => {
writer.setStyle(
"height",
"200px",
editor.editing.view.document.getRoot()
);
});
}}
/>
editor.ui.view.editable.editableElement.style.height = '300px';
From CKEditor 5 version 22 the proposed programmatic solutions are not working. Here it is how I get the work done:
ClassicEditor.create( document.querySelector( '#editor' ) )
.then( editor => {
editor.ui.view.editable.element.style.height = '500px';
} )
.catch( error => {
console.error( error );
} );
.ck-editor__editable {min-height: 500px;}
<div>
<textarea id="editor">Hi world!</textarea>
</div>
<script src="https://cdn.ckeditor.com/ckeditor5/22.0.0/classic/ckeditor.js"></script>
Add this to your stylesheet:
.ck-editor__editable {
min-height: 200px !important;
}
If you wish to do this programatically, the best way to do it is to use a Plugin. You can easily do it as follows. The following works with CKEditor 5 version 12.x
function MinHeightPlugin(editor) {
this.editor = editor;
}
MinHeightPlugin.prototype.init = function() {
this.editor.ui.view.editable.extendTemplate({
attributes: {
style: {
minHeight: '300px'
}
}
});
};
ClassicEditor.builtinPlugins.push(MinHeightPlugin);
ClassicEditor
.create( document.querySelector( '#editor1' ) )
.then( editor => {
// console.log( editor );
})
.catch( error => {
console.error( error );
});
Or if you wish to add this to a custom build, you can use the following plugin.
class MinHeightPlugin extends Plugin {
init() {
const minHeight = this.editor.config.get('minHeight');
if (minHeight) {
this.editor.ui.view.editable.extendTemplate({
attributes: {
style: {
minHeight: minHeight
}
}
});
}
}
}
This adds a new configuration to the CKEditor called "minHeight" that will set the editor minimum height which can be used like this.
ClassicEditor
.create(document.querySelector( '#editor1' ), {
minHeight: '300px'
})
.then( editor => {
// console.log( editor );
} )
.catch( error => {
console.error( error );
} );
I tried to set the height and width on the config but it just didn't work on the classic Editor.
I was able to change the height of the editor programmatically on Vue by doing this.
mounted() {
const root = document.querySelector('#customer_notes');
ClassicEditor.create(root, config).then(editor=>{
// After mounting the application change the height
editor.editing.view.change(writer=>{
writer.setStyle('height', '400px', editor.editing.view.document.getRoot());
});
});
}
Use css:
.ck.ck-editor__main .ck-content {
height: 239px;
}
Add this to your global stylesheet, this will increase the size of the CKEditor :)
.ck-editor__editable_inline {
min-height: 500px;
}
Just add it to the style tag.
<style>
.ck-editor__editable
{
min-height: 150px !important;
max-height: 400px !important;
}
</style>
As for configuring the width of the CKEditor 5:
CKEditor 5 no longer comes with a configuration setting to change its width but its width can be easily controlled with CSS.
To set width of the editor (including toolbar and editing area) it is enough to set width of the main container of the editor (with .ck-editor class):
<style>
.ck.ck-editor {
max-width: 500px;
}
</style>
Simply you can add this to your CSS file
.ck-editor__editable {min-height: 150px;}
Put this CSS in your global CSS file and the magic will happen. CkEditor is full of unsolved mysteries.
.ck-editor__editable_inline {
min-height: 400px;
}
Use max-height and min-height both. Beacuse max-height give scroll bar option after reached maximum mention height. Where min-height give static height to <textarea>.
.ck-editor__editable {
max-height: 400px; min-height:400px;}
If its in latest version of Angular say 12 or 12+. We can add below style to your components style file.
:host ::ng-deep .ck-editor__editable_inline { min-height: 300px; }
If you use jQuery and the CKEditor 5 has to be applied to a textarea, there is a "quick and dirty" solution.
The condition:
<textarea name='my-area' id='my_textarea_id'>
If you use jQuery the Editor call could be:
var $ref=$('#my_textarea_id');
ClassicEditor
.create( $ref[0] ,{
// your options
} )
.then( editor => {
// Set custom height via jQuery by appending a scoped style
$('<style type="text/css" scoped>.ck-editor .ck-editor__editable_inline {min-height: 200px !important;}</style>').insertAfter($ref);
} )
.catch( error => {
console.error( error );
} );
In other words, after rendering, you can address the same element used to build the editor and append after a scoped style tag with containing the custom height.
$('<style type="text/css" scoped>.ck-editor .ck-editor__editable_inline {min-height: 200px !important;}</style>').insertAfter($ref);
If you like to use a function (or some class method) to do this, you need something like this:
var editorBuildTo = function(id,options){
var options=options || {};
//Height represents the full widget height including toolbar
var h = options.height || 250; //Default height if not set
var $ref = $('#'+id);
h=(h>40?h-40:h);//Fix the editor height if the toolbar is simple
ClassicEditor
.create( $ref[0] ,{
// your options
} )
.then( editor => {
// Set custom height via jQuery
$('<style type="text/css" scoped>.ck-editor .ck-editor__editable_inline {min-height: '+h+'px !important;}</style>').insertAfter($ref);
} )
.catch( error => {
console.error( error );
} );
}
editorBuildTo('my_textarea_id',{
height:175,
// other options as you need
});
This works well for me
1.resource/assets/js/app.js
=================================
2.paste this code
=================================
require('./bootstrap');
//integrate
window.ClassicEditor = require('#ckeditor/ckeditor5-build-classic');
============================================
3.write on terminal
============================================
npm install --save #ckeditor/ckeditor5-build-classic
npm run watch
=======================================
4.in blade file
=======================================
<!DOCTYPE html>
<html lang="en">
<title></title>
<body>
<form action="{{route('admin.category.store')}}" method="post" accept-charset="utf-8">
#csrf
<div class="form-group row">
<div class="col-sm-12">
<label class="form-control-label">Description:</label>
<textarea name="description" id="editor" class="form-control" row="10" cols="80"></textarea>
</div>
</div>
</form>
<script>
$(function () {
ClassicEditor
.create( document.querySelector( '#editor' ), {
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' }
]
}
} )
.catch( error => {
console.log( error );
} );
})
</script>
</body>
</html>
click to show image here
Building on #Jaskaran Singh React solution. I also needed to ensure it was 100% height to it's parent. I achieved this by assigning a ref called "modalComponent" and further adding this code:
editor.editing.view.change(writer => {
let reactRefComponentHeight = this.modalComponent.current.offsetHeight
let editorToolbarHeight = editor.ui.view.toolbar.element.offsetHeight
let gapForgiveness = 5
let maximizingHeight = reactRefComponentHeight - editorToolbarHeight - gapForgiveness
writer.setStyle(
'height',
`${maximizingHeight}px`,
editor.editing.view.document.getRoot()
)
})
This CSS Method works for me:
.ck-editor__editable {
min-height: 400px;
}
I resolve this just adding in my layout page
<style>
.ck-content{
height: 250px;
}
</style>
Hope i help someone :D
For this particular version https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js,
the below code block worked for me.
.cke_contents { height: 500px !important; }
I guess the difference is just the fact that is it in plural.
In my case it worked for me
Add a ck class and write style like below:
<style>
.ck {
height: 200px;
}
</style>
Using plugin here I came up with this
let rows: number;
export class MinHeightPlugin {
constructor(public editor) {
}
init = function () {
this.editor.ui.view.editable.extendTemplate({
attributes: {
style: {
minHeight: (rows * 40) + 'px',
}
}
});
};
}
export const MinHeightPluginFactory = (rowss: number): typeof MinHeightPlugin => {
rows = rowss;
return MinHeightPlugin;
};
and the usage(4 rows each rows is considered 40px height):
this.editor.builtinPlugins.push(MinHeightPluginFactory(4));
I couldn't manage to make rows variable local to MinHeightPlugin, does anyone know how to do it?
.ck-editor__editable_inline {
min-height: 400px;
}
This makes height change for every editor used across all components. So it doesn't work in my case.
In Case of react js
<CKEditor
toolbar = {
[
'heading',
'bold',
'Image'
]
}
editor={ClassicEditor}
data={this.state.description}//your state where you save data
config={{ placeholder: "Enter description.." }}
onChange={(event, editor) => {
const data = editor.getData();
this.setState({
description : data
})
}}
onReady={(editor)=>{
editor.editing.view.change((writer) => {
writer.setStyle(
//use max-height(for scroll) or min-height(static)
"min-height",
"180px",
editor.editing.view.document.getRoot()
);
});
}}
/>
In order to enable both rich text editor and source mode to have the same height, use the following CSS:
.ck-source-editing-area,
.ck-editor__editable {
min-height: 500px;
}
.ck-editor__main {
height: 500px;
min-height: 500px;
max-height: 500px;
overflow-y: scroll;
border: 1px solid #bbbbbb;
}
Just test it's work. Hoping help you
var editor_ = CKEDITOR.replace('content', {height: 250});

Remove hyperlink from Kendo UI MVC Grid export

Does anyone know of a way to remove hyperlinks in the file generated from Kendo UI grid export to PDF and Excel functionality?
I have customised the export a fair amount and removed the pager bar etc, using CSS.
However I cannot work out how to stop the column headers from being hyperlinks.
I have tried setting the
pointer-events: none;
cursor: default;
but that didn't help and I am trying to avoid using javascript to remove it where possible.
UPDATE
Please see below an edited version of my grid code.
#(Html.Kendo().Grid<MvcProject.Domain.DTO.Reports.AccidentSummary>()
.Name("resultsGrid")
.Columns(columns =>
{
columns.Group(group => group
.Title("Accident Summary Report : Date run - " + DateTime.Now.ToShortDateString() )
.Columns(header => {
header.Bound(c => c.DocCount)
.HtmlAttributes(new { style = "text-align: center;" })
.Title(" ")
.ClientTemplate("<div><i rel='tooltip' title='Documents Attached' #= DocCount > 0 ? classHasFile : '' #></i></div>")
.Width(35).Filterable(false).Sortable(false).Groupable(false).IncludeInMenu(false);
header.Bound(c => c.RegionName)
.Title("Region")
.Width(100);
header.Bound(c => c.AreaName)
.Title("Area")
.Width(200);
header.Bound(c => c.Date_of_Accident)
.Title("Date")
.Width(120)
.Format("{0:dd/MM/yyyy}");
header.Bound(c => c.Days_Lost)
.Title("Days Lost")
.HtmlAttributes(new { style = "text-align: center;" })
.Width(120);
header.Bound(c => c.TypeOfAccidentName)
.Title("Nature ")
.Width(150);
header.Bound(c => c.Location_of_Accident)
.Title("Location Of Accident")
.Width(150).Hidden(true);
header.Bound(c => c.Comments)
.Title("Comments")
.Width(250).Hidden(true);
})
);
})
.HtmlAttributes(new { style = "height: 900px;" })
.Pageable(p => p
.ButtonCount(5)
.PageSizes(true)
.Refresh(true)
)
.Scrollable(s => s.Height("auto"))
.Sortable()
.Filterable()
.Groupable()
.ColumnMenu()
.Resizable(r => r
.Columns(true)
)
.Excel(excel => excel
.FileName("Accident Summary.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("_GridExportSave", "Reports"))
.AllPages(true)
)
.DataSource(d => d
.Ajax()
.Read(read => read.Action("_AccidentSummaryResults_Read", "Reports").Data("Genesis.Reports.HandS.Search.getPaginationData"))
.ServerOperation(true)
.PageSize(20)
)
.ToolBar(tools =>
{
tools.Pdf();
tools.Excel();
})
//PDF removed for now until it is patched
.Pdf(pdf => pdf
.AllPages()
.FileName("AccidentSummary.pdf")
.ProxyURL(Url.Action("_GridExportSave", "Reports"))
)
.Events(events => events.DataBound("Genesis.Reports.HandS.Search.loadTT"))
)
Try
<style>
.k-pdf-export .k-grid-toolbar,
.k-pdf-export .k-pager-wrap
{
display: none;
}
</style>
or
<style>
.k-grid-toolbar,
.k-grid-pager > .k-link
{
display: none;
}
</style>
Use pdf.avoidLinks(true) to skip the actual hyperlinks.
pdf.avoidLinks indicates whether to produce actual hyperlinks in the exported PDF file.
pdf.avoidLinks default value is false.
.Pdf(pdf => pdf
.AllPages()
.FileName("AccidentSummary.pdf")
.avoidLinks(true)
.ProxyURL(Url.Action("_GridExportSave", "Reports"))
)
Note: Available in versions 2015.3.1020 and later
For reference
With following you can easily hide excel export button from MVC Kendo Grid
$(".k-grid-excel").hide();

kendo grid rows are rendered with default style

My grid is
#(Html.Kendo().Grid<student.Models.SearchViewModel>()
.Name("Grid").HtmlAttributes(new { #class = "studentGrid" })
.Columns(
x =>
{
x.Bound(y => y.Id).Hidden(true);
x.Bound(y => y.Id).ClientTemplate(#"<input type='checkbox' name='checkedRecords' value='#= Id #' class='mainCheckbox' onclick='checkboxClicked(this, ""checkAllMain"")'/>")
.Title("")
.HeaderTemplate(#"<input type='checkbox' name='checkAllMain' onclick='selectAll(this, ""mainCheckbox"");' />")
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Filterable(false)
.Sortable(false)
.HtmlAttributes(new { #class = "checboxClass", style = "text-align:center" });
x.Bound(y => y.abc1).Hidden(false);
x.Bound(y => y.abc2).Hidden(false);
x.Bound(y => y.abc3).Hidden(false);
}
)
.ToolBar(tb =>
{
tb.Custom()
.Text("Export To Excel")
.HtmlAttributes(new { id = "export" })
.Url(Url.Action("Export", Html.CurrentControllerName()));
tb.Custom()
.Text("Expand Selected Rows")
.HtmlAttributes(new { id = "expandSelectedRows" });
})
.Groupable()
.Reorderable(x => x.Columns(true))
.Pageable(x => x.PageSizes(new int[] { 20, 50, 100 }).Input(true).Numeric(true))
.Scrollable(x => x.Enabled(true).Height(Model.Height))
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable()
.Selectable()
.Navigatable()
.Filterable()
.ClientDetailTemplateId("subTemplate")
.AutoBind(!Model.NoAutoload)
.Events(ev => { ev.DataBound("DataBoundSearch"); })
.DataSource(dataSource => dataSource
.Ajax().PageSize(100)
.ServerOperation(false) // Paging, sorting, filtering and grouping will be done client-side
.Model(model => model.Id(c => c.Id))
.Events(events => events.Error("error").RequestStart("RequestStart").RequestEnd("RequestEnd").Change("Changed"))
.Read(x => x.Action("GetData", Html.CurrentControllerName()).Data("ABCPostData")))
)
with kendo grid when we select a row that row is highlighted with brown color by default.Am not able to get the default color when row is clicked. On the client side it rendered as
<tr class="k-master-row k-state-selected" data-uid="122bb914-87c2-4f0c-9351-52c1d9b84ae5" style="background-color: rgb(255, 255, 255);">
how it is set to background-color: rgb(255, 255, 255); ? how can i override this to brown like background-color: #f0713a, border-color: #f0713a?
There are a couple of ways to do this. The easiest way is through CSS
Modifying style for selected row
#grid tr.k-state-selected td {
background-color: #f0713a;
border-color: #f0713a
}
Modifying style for selected cell
#grid td.k-state-selected {
background-color: #f0713a;
border-color: #f0713a
}
and in your grid declaration ensure this is set:
selectable: "cell"
Here is a demo for single cell.
Another way is to override kendo styles with their themebuilder. But this is extremely bulky.
If you want to do it programatically, this is possible too by getting the selected element in the change event of the grid, and then setting the element's background in code. I will try to do this if you need this option, but the way I see it, leave UI stuff to css, and leave coding to javascript.

Kendo UI Cascading Dropdown initial value not setting up

I have cascade dropdownlists and when trying to define initial value (under cascade, too) instead to call the ajax controller methods with parent selected value it's passing blank values.
I have equirement like, i can save my last search values and store it int database and after coming to that screen again, values will be selected by default.
Everything is in Javascript means storing the values/ retriving and applying to controls :
My Cascade dropdown code :
<div style="width: 400px; clear: both; float: left; position: relative; display: table-cell;">
<ul style="width: 450px; clear: both; float: none;">
<li>
<div class="editor-row">
<div class="editor-label-short">Home Country</div>
<div class="editor-field">
#(Html.Kendo().DropDownList()
.Name("HOME_COUNTRY_ID")
.HtmlAttributes(new { style = "width:200px" })
.OptionLabel("Select Home Country")
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source => source.Read(read => read.Action("GetCountryJSON", "Employee")))
)
</div>
</div>
</li>
<li>
<div class="editor-row">
<div class="editor-label-short">Home City</div>
<div class="editor-field">
#(Html.Kendo().DropDownList()
.Name("HOME_CITY_ID")
.HtmlAttributes(new { style = "width:200px" })
.OptionLabel("Select Home City")
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source => source.Read(read => read.Action("GetCityByCountryJSON", "Employee")
.Data("getCountryId"))
.ServerFiltering(true))
.AutoBind(false)
.CascadeFrom("HOME_COUNTRY_ID")
)
</div>
</div>
</li>
</ul>
</div>
Javacript Code which assigning Values in Page load means After Dom ready:
function applyvaluetoControls() {
setdefaultvaluestoControls();
$.each(activeLayout.controls, function(index) {
$.each(options.emementArray, function(innerindex) {
if (options.emementArray[innerindex].attr("id") === activeLayout.controls[index]["id"]) {
if ((options.emementArray[innerindex]).is(':checkbox')) {
options.emementArray[innerindex].prop('checked', activeLayout.controls[index]["value"]);
} else {
if (options.emementArray[innerindex].attr("data-role") !== undefined && options.emementArray[innerindex].attr("data-role") === "dropdownlist") {
// console.log(options.emementArray[innerindex].data('kendoDropDownList'));
if (options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom !== "") {
console.log($("#" + options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom).val());
options.emementArray[innerindex].data('kendoDropDownList').dataSource.read({ CompanyId: $("#" + options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom).val() });
options.emementArray[innerindex].data('kendoDropDownList').value(activeLayout.controls[index]["value"]);
} else {
options.emementArray[innerindex].data('kendoDropDownList').enable();
options.emementArray[innerindex].data('kendoDropDownList').value(activeLayout.controls[index]["value"]);
}
console.log(activeLayout.controls[index]["id"]);
console.log(activeLayout.controls[index]["value"]);
} else {
options.emementArray[innerindex].val(activeLayout.controls[index]["value"]);
}
}
}
});
});
}
Console Log:
HOME_COUNTRY_ID // Parent Control Id
322 // It Setting the value to Parent
// Blank value when I am trying to read the value Parent Control (Country)
City : // Parent triggering Chile but with Blank Value
HOME_CITY_ID // Child
342 // Value
City : 322 // after coming out of loop it's again calling Child with Parent selected value
and It's wiping out intial selected value of child.
Any help will be highly appreciated!!
ChildrenUsing these properties from your example in your child drop down you are instructing the drop down to:
.AutoBind(false) //<--Don't do any data retrieval until asked or clicked
.OptionLabel("Select Home City") //<--If the value is null display this and value will be ""
.CascadeFrom("HOME_COUNTRY_ID") //<--Get my values using the DataValueField from this control and refresh when it changes
I bet by having the cascade on like that you will need a configuration similar to this fictitious scenario:
Parent DropDown Config
.Name("ddlParent")
.OptionLabel((#Model.ForceParentSelect) ? "" : "All Parents")
.Value(Model.ParentID.HasValue ? Model.ParentID.Value.ToString() : "")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetParents", "Parent");
});
})
Child DropDown Config
<script>
function filterChild{ return { ParentID: $("#ddlParent").val() }; }
</script>
.Name("ddlChild")
.OptionLabel((#Model.ForceChildSelect) ? "" : "All Childs")
.Value(Model.ChildID.HasValue ? Model.ChildID.Value.ToString() : "")
.AutoBind(Model.ParentID.HasValue)
.CascadeFrom(Model.ParentID.HasValue ? "" : "ddlParent")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetChildren", "Child")
.Data("filterChild");
})
})

Kendo.UI Grid Change row color on hover

I have a Kendo Grid declared inside of a Kendo Splitter like this in my partial view.
#(Html.Kendo().Splitter()
.Name("adminSplitter")
.Orientation(SplitterOrientation.Horizontal)
.Panes(p =>
{
p.Add()
.HtmlAttributes(new
{
id = "adminLeftHandPane"
})
.Resizable(false)
.Size("150px")
.Content(#<text>
#(Html.Kendo().Grid<AdministrativeTask>()
.Name("grdAdminTasks")
.ClientRowTemplate("<tr class=\"gridRow\"><td style=\"cursor:pointer\"><img src=\"#=ImageUrl#\" style=\"height: 16px; width: 16px;\" /> #=Title#</td></tr>")
.Columns(c => c.Bound(i => i.Action)
.Title("Administrative Tasks"))
.Selectable(s => s.Mode(GridSelectionMode.Single))
.DataSource(ds => ds.Ajax().Read("LoadAdministrativeTasks", "Admin").ServerOperation(false))
.Events(e => e.Change("change"))
)
</text>);
p.Add()
.HtmlAttributes(new
{
id = "adminRightHandPane"
})
.Content(#<text>
<div id="adminRightHandPaneContent"></div>
</text>)
;
}
)
)
and in this same partial view my script looks like this
<script>
function change() {
var row = this.select();
var item = this.dataItem(row);
$.ajax({
url: '/' + item.Controller + '/' + item.Action,
contentType: 'application/html; charset=utf-8',
type: 'GET',
dataType: 'html',
cache: false,
})
.success(function (result) {
// Display the section contents.
$('#adminRightHandPaneContent').html(result);
})
.error(function (xhr) {
$('#adminRightHandPaneContent').html("ERROR: <br><br>" + xhr.responseText);
//alert(xhr.responseText);
});
}
$(document).ready(function () {
alert($('.gridRow'));
$(".gridRow").hover(
function () {
alert("hit");
$(this).addClass("highlightRow");
},
function() {
$(this).removeClass("highlightRow");
}
);
});
When the partial view loads I get the alert "[object Object]" which tells me that Jquery found the row. However, when I hover over the row in question I do not get the "hit" alert message so at this point I am at a loss on how to proceed.
I am trying to get the row highlighted when the user hovers over the row. What am I doing wrong?
If you just want to change the styling of a row when the cursor is over the row of table, you can simply define a CSS style as:
#grid tbody tr:hover {
background: #ff0000;
}
Where grid is the id of the grid.
See if running here http://jsfiddle.net/OnaBai/uN2W5/
So you don't even need to add a CSS classes, hover function handlers,...
in generic form:
.k-grid table tr:hover td {
background :rgb(107, 188, 242) !important;
cursor: pointer !important;
}
in Q1 2016
kendo ui has in the css this line
.k-grid tr:hover{background-image:url(textures/highlight.png);background-image:none,-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,.45)),to(rgba(255,255,255,0)));background-image:none,-webkit-linear-gradient(top,rgba(255,255,255,.45) 0,rgba(255,255,255,0) 100%);background-image:none,linear-gradient(to bottom,rgba(255,255,255,.45) 0,rgba(255,255,255,0) 100%);background-color:#88c5e0}
so it should work out of the box
.k-grid table tr.k-state-selected{background: red;color: black; }

Resources