Kendo ui grid auto height - asp.net-mvc-4

I am currently implementing the same kendoui grid as showing in the following:
http://demos.kendoui.com/web/grid/index.html
The problem that i can see is that the grid does not have auto height where if the record less than 10, the grid still in the same height.
Is there anyway i could resolve this since this one not happening when we use the previous version
I tried using the following javascript but still not working:
function resizeGrid() {
var gridElement = $("#grid");
var dataArea = gridElement.find(".k-grid-content");
var newGridHeight = $(document).height() - 350;
var newDataAreaHeight = newGridHeight - 65;
dataArea.height(newDataAreaHeight);
gridElement.height(newGridHeight);
$("#grid").data("kendoGrid").refresh();
}
$(window).resize(function () {
resizeGrid();
});
Thank you

Not sure I understand your problem because the Grid actually has an autoheight. If in the definition of the Grid you define an attribute saying the number of pixel that grid should have, it will stick to that height no matter it it has 5 or 50 records. If it actually needs more space will add a scrollbar and if it need less, it will display the empty space.
In the example that you refer in your question try:
$("#grid").kendoGrid({
dataSource: {
data : createRandomData(20),
pageSize: 10
},
height : 500,
groupable : true,
sortable : true,
pageable : {
refresh : true,
pageSizes: true
},
columns : [
{ field: "FirstName", width: 90, title: "First Name" } ,
{ field: "LastName", width: 90, title: "Last Name" } ,
{ width: 100, field: "City" } ,
{ field: "Title" } ,
{ field : "BirthDate", title : "Birth Date", template: '#= kendo.toString(BirthDate,"dd MMMM yyyy") #' } ,
{ width: 50, field: "Age" }
]
});
And the height will be 500px.

You can use css in order to draw a grid that will keep its height adjusted to its container, as well as considering other elements around:
#grid {
/* chop the grid's height by 45px */
height: calc(100% - 45px);
}
#grid .k-grid-content {
/* chop the grid content's height by 25px */
height: calc(100% - 25px) !important;
}
This is done without using the 'height' property in the grid's declaration (at the .js side).
Works fine for me.

Remove height: 500
$("#grid").kendoGrid({
dataSource: {
data : createRandomData(20),
pageSize: 10
},
groupable : true,
sortable : true,
pageable : {
refresh : true,
pageSizes: true
},
columns : [
{ field: "FirstName", width: 90, title: "First Name" } ,
{ field: "LastName", width: 90, title: "Last Name" } ,
{ width: 100, field: "City" } ,
{ field: "Title" } ,
{ field : "BirthDate", title : "Birth Date", template: '#= kendo.toString(BirthDate,"dd MMMM yyyy") #' } ,
{ width: 50, field: "Age" }
]
});

For me, removing scrollable did the trick.
If there was only one row, the grid was small, and grew together with the amount of rows up to the pagesize level.
No height setting needed.

Related

dgrid onDemandGrid renders larger than the space it's in, therefore causing vertical scrolling

I'm trying to render the dgrid without the vertical scrollbar showing up, but for some reason, it always renders larger than the space it's in.
When the grid loads, it renders at 400x300 even though the space is only 300x200 which then causes vertical scrolling. How do I prevent that?
addGrid: function () {
this.grid = (declare([OnDemandGrid, Selection]))({
id: "tgrid" + this.reportId,
loadingMessage: 'Loading data...',
noDataMessage: 'No results found.',
allowTextSelection: true,
scroller: true,
collection: new Memory({
idProperty: "id"
}),
columns: {
trackName: "Name",
urn: {
label: "URN",
renderCell: function(object, value, cell) {
if(typeof value === 'undefined' ) {
cell.bgColor = "red";
} else {
cell.innerHTML = value;
}
}
},
location: "Location",
affiliation: "Affiliation",
eta: "ETA",
lta: "LTA"
}
}, this.gridId);
//next get the tracks using this call
this.getTracks();
}
.dgrid {
height: auto;
}
.dgrid-row {
padding: 3px 0 2px 9px;
}
.dgrid-scroller {
position: relative;
overflow: auto;
max-height: 95%;
}

How do I put Icons in the y Axis for a Dynamic Highcharts chart?

Does anyone have an example for Dynamic Highcharts where the y axis uses icons (smiley/frowney faces for example) instead of alphanumeric characters?
You need to set useHTML true in formatter function of yAxis label.See the code below and working fiddle here
for dynamic image, you can put image path as variable. If you don't want to show axis value remove "this.value" from formatter function
yAxis: { labels: {
formatter: function() {
return '<img src="http://highcharts.com/demo/gfx/sun.png" alt="" style="vertical-align: middle; width: 32px; height: 32px"/>'+ this.value;
},
useHTML: true
}
}
Just in case anyone else is looking for making a chart with y axis having multiple images, here's how I did it:
var chartScales = scales.map(function(x){ return { value:x.Text, key:++imageIndex, image:x.DefaultImage }; });
var chart = $("#chartContainer").highcharts({
chart: {
type: 'spline'
},
yAxis:{
categories: chartScales,
labels: {
formatter : function()
{
// if there's an image use it, otherwise use the text, or key value
if(this.value.image != null)
return "<img src='"+ this.value.image +"' style='vertical-align: middle; width: 32px; height: 32px'/>"+(this.value.value != null ? this.value.value : this.value.key);
return this.value.value != null ? this.value.value : this.value.key;
},
useHTML: true
}
},
series: [{
data: []
}]
});

SignalR values with Kendo UI Asp.net wrappers

I have a Kendo UI datawiz component, RadialGauge, which I would like to feed with real time data. It's setup using the asp.net wrappers, like so (snipped from kendo demos):
<div id="gauge-container-center">
#(Html.Kendo().RadialGauge()
.Name("tensionGauge")
.Pointer(pointer => pointer.Value(28))
.Scale(scale => scale
.MinorUnit(5)
.StartAngle(-60)
.EndAngle(240)
.Max(180)
.Labels(labels => labels
.Position(GaugeRadialScaleLabelsPosition.Inside)
)
.Ranges(ranges =>
{
ranges.Add().From(80).To(120).Color("#ffc700");
ranges.Add().From(120).To(150).Color("#ff7a00");
ranges.Add().From(150).To(180).Color("#c20000");
})
)
)
</div>
All the underlying functionality is for "real time" data is setup and working fine. My only issue is how I would go about feeding the signalR value into the .Pointer(pointer => pointer.Value(signalRValueHere) part. Any suggestions on how to do this? It doesn't seem to be an abundance of examples combining these two frameworks yet, so search results are scarce.
Ok, so I solved this using a different approach. I opted to use the javascript-initializer instead, allowing me to utilize SignalR-values in the script.
function createGauge() {
$("#tensionGauge").kendoRadialGauge({
pointer: {
value: 0,
color: "black",
},
cap: {
color: "white",
size: 1
},
scale: {
minorUnit: 50,
majorUnit: 100,
startAngle: -50,
endAngle: 230,
min: #Convert.ToInt32(Model.MinTensionRange),
max: #Convert.ToInt32(Model.MaxTensionRange),
labels: {
position: "inside"
},
ranges: [ // TODO: Fetch limits from signalR or Model
{
from: 300,
to: 100,
color: "#ffc700"
},{
from: -300,
to: -100,
color: "#ffc700"
}, {
from: #Convert.ToInt32(Model.MinTensionRange),
to: -300,
color: "#c20000"
},{
from: #Convert.ToInt32(Model.MaxTensionRange),
to: 300,
color: "#c20000"
}
]
}
});
}
$(document).ready(function () {
createGauge();
});
And the js-part to update the value:
messageHub.client.notifyTension = function (tensionMessage) {
$('#tensionGauge').data("kendoRadialGauge").value(tensionMessage);
};

SenchaTouch onItemDisclosure 2 icons

I have a list and I want have two icons per line using onItemDisclosure. How can I do that?
I don't know how to implement onItemDisclousre() on two icons but probably this will help you.
In the following example i have put an image on every itemlist and functionality is provided on itemtap event. This will serve the purpose of doing multiple tasks with single itemlist.
//demo.js
Ext.define("Stackoverflow.view.demo", {
extend: "Ext.Container",
requires:"Ext.dataview.List",
alias: "widget.demo",
config: {
layout: {
type: 'fit'
},
items: [
{
xtype: "list",
store: "store",
itemId:"samplelist",
loadingText: "Loading Notes...",
emptyText: "<div class=\"notes-list-empty-text\">No notes found.</div>",
onItemDisclosure: true,
itemTpl:"<div class='x-button related-btn' btnType='related' style='border: none; background: url(\"a.png\") no-repeat;'></div>"+
"<div class=\"list-item-title\">{title}</div>"
grouped: true
}
],
listeners:
[
{
delegate: "#samplelist",
event: "disclose",
fn: "onDiscloseTap"
}
]
},
onDiscloseTap: function (list, record, target, index, evt, options) {
this.fireEvent('ondisclosuretap', this, record);
}
});
// Democontrol.js
Ext.define("Stackoverflow.controller.Democontrol", {
extend: "Ext.app.Controller",
config: {
refs: {
// We're going to lookup our views by xtype.
Demo: "demo",
Demo1: "demo list",
},
control: {
Demo: {
ondisclosuretap: "Disclosure",
},
Demo1: {
itemtap:"imagetap"
}
}
},
Disclosure: function (list, record,target,index,e,obj) {
Ext.Msg.alert('','Disclosure Tap');
},
imagetap: function (dataview,index,list,record, tar, obj) {
tappedItem = tar.getTarget('div.x-button');
btntype = tappedItem.getAttribute('btnType');
if(btntype == 'related')
{
Ext.Msg.alert('','Image/Icon Tap');
}
},
// Base Class functions.
launch: function () {
this.callParent(arguments);
},
init: function () {
this.callParent(arguments);
}
});
//app.css
.related-btn
{
width: 100px;
height: 100px;
position: absolute;
bottom: 0.85em;
right: 2.50em;
-webkit-box-shadow: none;
}
Hope this will help you.
bye.
You can do this by manually adding a disclosure icon inside of itemTpl on your list items. Add this inside of your view:
{
xtype: 'list',
onItemDisclosure: true,
cls: 'my-list-cls',
itemTpl: [
'<div class="x-list x-list-disclosure check-mark" style="right: 48px"></div>'
]
}
Notice that the div inside of itemTpl has the CSS class "x-list x-list-disclosure check-mark". I set style="right: 48px" because I want this icon to appear on the left side of the regular disclosure icon (the one with the right arrow) and this rule leaves enough room on the right to show the arrow icon.
Then, in your app.scss, add:
.my-list-cls {
.x-list.check-mark.x-list-disclosure:before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: '3';
font-family: 'Pictos';
color: #fff;
text-align: center;
text-shadow: 0 0 0;
}
}
This controls the styling for your new disclosure icon.
By setting content: '3';, you are changing the icon from the default right arrow to a checkmark. (See all of the available icons here: Pictos fonts).
The result:
It is possible but not easy. In short you have to extend class Ext.dataview.List and/or Ext.dataview.element.List.

id for buttons in datagrid

I have the following code for adding buttons in ever row of a DataGrid:
structure: [
{field: 'msConstId', width: '0%', name: 'Milestone',hidden: true},
{field: 'edit', width: '8%', name: 'Edit',formatter: function(data, rowIndex) {
return new dijit.form.Button({style: "width: 80px;",label:"Edit", iconClass:"dijitIconEditTask",showLabel:true, onClick:function(){ updateMilestone.show(); populateUpdateControls(); }});
}},
{field: 'delete', width: '10%', name: 'Delete',formatter: function(data, rowIndex) {
return new dijit.form.Button({style: "width: 80px;",label:"Delete", iconClass:"dijitIconDelete",showLabel:true, onClick:function(){ deleteMilestoneDialog(); }});
}}
]
The problem is that I want to assign an id to each of the button as "editBtnRowIndex" and "deleteBtnRowIndex". I want to use the id's for enabling and disabling buttons in specific grid rows.
Is that possible?
I had to go with a work around for this by looking at the data in other fields and disabling the button for that row with something like this:
var rowdata = grid.getItem(rowIndex);
rowIndex is passed as param to formatter function.
var val = rowdata.myRowID;
if(val=='specific value') {
//return disabled button
} else {
//return enabled button
}