GRİD CODE
I run the program grid height too small but when I minimize or mazimize page grid cover page and normal height. How to grid height 100% when page load?
<div class="portlet-body form" >
#(Html.Kendo().Grid<DoktorModel>()
.Name("DoktorGrid")
.Columns(columns =>
{
columns.Bound(p => p.Fotograf).ClientTemplate(#"<img class='doktor_photo' src='" + Url.Content("~/Photo/#:data.Fotograf#") + "'/>").Width(100).Title("Fotoğraf").Filterable(false).IncludeInMenu(false);
columns.ForeignKey(p => p.AkademikUnvanKodId, Kod.GetKodList((int)Enums.KodGrup.AkademikUnvan), "KodId", "Aciklama").Width(200).ClientGroupHeaderTemplate("Akademik Unvan: #= foreignAkademikValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.Bound(p => p.Ad).Width(200).ClientGroupHeaderTemplate("Ad: #= value # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.Bound(p => p.Soyad).Width(200).Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.AnadalUzmanlikId, Uzmanlik.GetUzmanlikList(), "UzmanlikId", "UzmanlikAdi").Width(215).ClientGroupHeaderTemplate("Anadal Uzmanlik: #:foreignAnadalValues[value]# (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.GorevKurumId, Kurum.GetKurumCombo(), "KurumId", "Ad").Width(215).ClientGroupHeaderTemplate("Gorevli Olduğu Kurum: #= foreignGorevKValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.KadroKurumId, Kurum.GetKurumCombo(), "KurumId", "Ad").Width(215).ClientGroupHeaderTemplate("Kadro Kurum: #= foreignKadroKValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.KadroUnvanKodId, Kod.GetKodList((int)Enums.KodGrup.ÇalıştığıUnvan), "KodId", "Aciklama").Width(215).ClientGroupHeaderTemplate("Kadro Unvan: #= foreignKadroUValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.CalistigiUnvanKodId, Kod.GetKodList((int)Enums.KodGrup.ÇalıştığıUnvan), "KodId", "Aciklama").Width(180).ClientGroupHeaderTemplate("Çalıştığı Unvan: #= foreignCalisanUValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.ForeignKey(p => p.IdariGorevUnvan, Kod.GetKodList((int)Enums.KodGrup.IdariGorevUnvan), "KodId", "Aciklama").Width(180).ClientGroupHeaderTemplate("İdari Görev Unvan: #= foreignIdariGorevValues[value] # (Sayı: #= count#)").Filterable(ftb => ftb.Multi(true));
columns.Bound(p => p.DocentlikTarihi).Format("{0:dd/MM/yyyy}")
;
})
.ToolBar(tools => tools.Excel().Text("Excel Dosyası Olarak Kaydet"))
.ToolBar(t=>t.Custom().Text("Grupları Aç").HtmlAttributes(new { id = "GrupAc" }))
.ToolBar(t=>t.Custom().Text("Grupları Kapat").HtmlAttributes(new { id = "GrupKapat", type = "button", onclick = "GrupKapat(); return false;" }))
//.Pageable(x => x.Info(true))
.Resizable(x => x.Columns(true))
.ColumnMenu()
.Selectable()
.Sortable()
.Scrollable(scrollable => scrollable.Virtual(true))
.Excel(excel => excel
.FileName("Kendo UI Grid Export.xlsx")
.AllPages(true)
.ProxyURL(Url.Action("Doktor_Excel_Export_Save", "Doktor"))
)
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("İçerir")
)).Mode(GridFilterMode.Row))
.Groupable()
.Events(events => events.DataBound("datachange")
)
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(100)
//.Batch(false)
.Events(e => e.Error("error_handler"))
.Read(read => read.Action("Doktor_Read", "Doktor").Type(HttpVerbs.Post))
//.PageSize(20)
.Aggregates(aggregates =>
{
aggregates.Add(p => p.AkademikUnvanKodId).Count();
aggregates.Add(p => p.Ad).Count();
aggregates.Add(p => p.AnadalUzmanlikId).Count();
aggregates.Add(p => p.GorevKurumId).Count();
aggregates.Add(p => p.KadroKurumId).Count();
aggregates.Add(p => p.CalistigiUnvanKodId).Count();
aggregates.Add(p => p.KadroUnvanKodId).Count();
aggregates.Add(p => p.IdariGorevUnvan).Count();
})
.Model(m =>
{
m.Id(p => p.DoktorId);
m.Field(p => p.TCKimlikNo);
m.Field(p => p.Ad);
m.Field(p => p.Soyad);
m.Field(p => p.AkademikUnvanKodId);
m.Field(p => p.DocentlikTarihi);
m.Field(p => p.AnadalUzmanlikId);
m.Field(p => p.AnadalUzmanlikId2);
m.Field(p => p.YandalUzmanlikId);
m.Field(p => p.YandalUzmanlikId2);
m.Field(p => p.GorevKurumId);
m.Field(p => p.KadroKurumId);
m.Field(p => p.KadroUnvanKodId);
m.Field(p => p.CalistigiUnvanKodId);
m.Field(p => p.CalistigiUnvanKodId2);
m.Field(p => p.DayanakDurumKodId);
m.Field(p => p.Fotograf);
})))
</div>
MY SCREENSHOT
this is my screenshot when page loaded...
I put the resize function in ondatabund function but it is not working. function ondatabund () { $(window).resize(function () { var gridElement = $("#DoktorGrid"), ... }); }
You are attaching a window.resize handler in dataBound, but this does not mean it will be executed - it won't. So execute the Grid's resizing routine manually in dataBound as well.
I solve the problem give heigth to grid in databound function.
function databound() {
var gridElement = $("#DoktorGrid"),
newHeight = gridElement.innerHeight(),
otherElements = gridElement.children().not(".k-grid-content"),
otherElementsHeight = 0;
//otherElements.each(function () {
otherElementsHeight += $(".page-content").outerHeight();
console.log("outerHeight" + $(".page-content").outerHeight() + "newHeight" + newHeight)
//});
gridElement.children(".k-grid-content").height( otherElementsHeight-290 );//290 grid outher elements height
}
Related
I have a kendo grid with filter operators on it. the problem is that the filters are extending beyond the grid with and resulting in a view which makes them look cut off where the column ends. Here is an image:
Code:
<div id="gridDiv">
#(Html.Kendo().Grid<Website.Models.VisitModel.VisitGridModel>()
.Name("grid")
.ToolBar(toolbar =>
{
toolbar.Custom().Text("Create").Action("AddPatient", "Patient").HtmlAttributes(new { #class = "k-primary k-button" });
})
.Columns(column =>
{
column.Bound(c => c.DateS);
column.Bound(c => c.PreScreening);
column.Bound(c => c.Screening);
column.Bound(c => c.ReadyMadeReaders);
column.Bound(c => c.EyeExam);
column.Bound(c => c.Glasses);
column.Bound(c => c.Contacts);
column.Bound(c => c.RetinalGrading);
})
.Events(e =>
{
})
.Sortable()
.Scrollable()
.Selectable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.NoRecords("No data")
//.ClientDetailTemplateId("template")
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Filterable(f => f.Operators(o => o.ForString(fs => fs.Clear().Contains("Contains").StartsWith("Start With").EndsWith("End with").IsEqualTo("Is equal to").IsNotEqualTo("Is not equal to"))))
.Pageable(page => page
.Refresh(true)
.ButtonCount(5)
.PageSizes(new string[] { "5", "10", "20", "100", "All" })
)
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Sort(s =>
{
s.Add(a => a.ID).Ascending();
})
.Model(model =>
{
model.Id(i => i.ID);
})
.Read("ReadAllVisits", "EyeTestReport")
.Events(events => events.Error("Shared.onGridDataSourceError").RequestEnd("Shared.onGridRequestEnd"))
)
)
How can I get the columns to be the right size?
I found out you simply have to override kendo's styling in the pages own styling file or styling tag. like this:
.k-grid-header .k-header:first-child {
border-left-width: 0;
width: 50% !important;
}
Screen:
column.Bound(c => c.DateS).Width(150);
column.Bound(c => c.PreScreening).Width(150);
column.Bound(c => c.Screening).Width(150);
try adding width to the column bound and see will resolve your issue...
I have a question based on my current situation, I have a grid with ClientDetail / Child grid inside of it. In my parent grid there is a custom command button, let say...
"columns.Command(
command => { command.Custom("Edit").Click("showEdit"); command.Destroy();
}).Width(160);"
and also i had my custom command button as well in my child grid, let say...
"columns.Command(
command => { command.Custom("Edit").Click("showSubEdit"); command.Destroy();
}).Width(160);"
Those 2 custom command should call different function which is "showEdit" & "showSubEdit". The problem is, every time custom command in child grid triggered, it always calls its parent's function which is "showEdit", however the child grid should call "showSubEdit".
Is there something i missed ?
NB :
function showEdit(e) {
...
}
function showSubEdit(e) {
...
}
Grid Code :
<div>
#(Html.Kendo().Grid<ActivityModel>()
.Name("GridActivity")
.Columns(columns =>
{
//columns.Template(t => { }).Title("No").ClientTemplate("#= renderNumber(data) #").Width(50);
columns.Bound(c => c._id).Visible(false);
columns.Bound(c => c.ActivityType.TypeTitle).Title("Type").Width(80);
columns.Bound(c => c.ActivityTitle).Title("Title").Width(120);
columns.Bound(c => c.DependenciesStr).Title("Dependencies").Width(120);
columns.Bound(c => c.ResourcesStr).Title("Resources").Width(120);
columns.Bound(c => c.FromStr).Title("From");
columns.Bound(c => c.ToStr).Title("To");
columns.Bound(c => c.Status).Title("Status").Width(90).Format("{0:0.00} %").Width(85);
columns.Bound(c => c.Weight).Title("Weight").Format("{0:0.00} %").Width(85);
columns.Command(command => { command.Custom("Edit").Click("showEdit"); command.Destroy(); }).Width(160);
})
.HtmlAttributes(new { style = "height: 290px;" })
.Groupable()
.Scrollable()
.Sortable()
.Filterable()
.ClientDetailTemplateId("template")
.Pageable(x => x.PageSizes(new int[] { 10, 20 }).Refresh(true))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(c => c.Id(p => p._id))
.Read(read => read.Action("ProjectActivities_Read", "Project", new { projectId = ViewBag.ProjectId }))
.Destroy(destroy => destroy.Action("ProjectActivities_Destroy", "Project", new { projectId = ViewBag.ProjectId }))
)
.Events(x => x.DataBound("resetRowNumber"))
)
</div>
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().TabStrip()
.Name("TabStrip_#=_id#")
.SelectedIndex(0)
.Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
.Items(items =>
{
items.Add().Text("Sub Activity").Content(#<text>
#(Html.Kendo().Grid<ActivityModel>()
.Name("GridChild_#=_id#")
.Columns(columns =>
{
columns.Bound(x => x._id).Visible(false);
columns.Bound(x => x.ActivityType.TypeTitle).Title("Type");
columns.Bound(x => x.ActivityTitle).Title("Title").Width(150);
columns.Bound(x => x.DependenciesStr).Title("Dependencies").Width(150);
columns.Bound(x => x.ResourcesStr).Title("Resources").Width(150);
columns.Bound(x => x.FromStr).Title("From");
columns.Bound(x => x.ToStr).Title("To");
columns.Bound(x => x.Status).Title("Status").Width(90).Format("{0:0.00} %").Width(85);
columns.Bound(x => x.Weight).Title("Weight").Format("{0:0.00} %").Width(85);
columns.Command(command => { command.Custom("Edit").Click("showEditSub"); command.Destroy(); }).Width(160);
})
.Pageable(x => x.PageSizes(new int[] { 5, 10 }).Refresh(true))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Model(x => x.Id(y => y._id))
.Read(read => read.Action("ProjectSubActivities_Read", "Project", new { projectId = ViewBag.ProjectId, activityId = "#=_id#" }))
.Destroy(destroy => destroy.Action("ProjectSubActivities_Destroy", "Project", new { projectId = ViewBag.ProjectId, activityId = "#=_id#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate())
</text>
);
}).ToClientTemplate())
</script>
I got around the bubbling by checking if the element shown by the first command event is visible:
function showDetailsLevel(e) {
e.preventDefault();
originatingId = this.dataItem($(e.currentTarget).closest("tr")).Id
var wnd = $("#Details").data("kendoWindow");
if (!$("#Details").is(":visible")) {
wnd.center();
wnd.open();
var grid = $("#DetailGrid").data("kendoGrid");
grid.dataSource.read();
}
}
I am trying to get the action link working in this code. Afraid I am an absolute novice so need help desperately.
The link simply has to call a small managing window linked to the UnderwriterID which would be the UserName.
#(Html.Kendo().Grid<QMS.ViewModels.UnderwriterVM>()
.Name("Grid1")
.Columns(columns =>
{
columns.Bound(p => p.PortfolioID).Width(100);
columns.Bound(p => p.UnderwriterID).Width(100);
columns.Bound(p => p.UWName).Width(100);
columns.Bound(p => p.UWLastName).Width(100);
columns.Bound(p => p.PremiumAuthority).Width(100);
columns.Bound(p => p.DiscountAuthority).Width(100);
columns.Bound(p => p.UW_ShortID).Width(100);
columns.Bound(p => p.MaxDiscount).Width(100);
columns.Template(p => #Html.ActionLink("Manage", "ManageUW", new { pfid = ViewBag.PF, uwid = Model.FirstOrDefault().UserName }));
columns.Command(command => { command.Destroy(); }).Width(110);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
//.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(430))
.Filterable()
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Create("Underwriters_Create", "Grid")
.Update("Underwriters_Update", "Grid")
.Destroy("Underwriters_Destroy", "Grid")
.Read("Read_Underwriters", "Grid", new { vPortId = ViewBag.PF} )
.Model(model =>
{
model.Id(p => p.UnderwriterID);
model.Field(p => p.PortfolioID).DefaultValue(ViewBag.PF);
model.Field(p => p.UWName).Editable(true);
model.Field(p => p.UWLastName).Editable(true);
model.Field(p => p.PremiumAuthority).Editable(true);
model.Field(p => p.DiscountAuthority).Editable(true);
}))
)
Here is what my column client templates look like:
columns
.Bound(p => p.UserName)
.Title("")
.Filterable(false)
.Sortable(false)
.Width(103)
.ClientTemplate(Html.ActionLink("<span class=\"k-icon k-i-pencil\"></span>Manage", "ManageUW", "YourController", new { pfid = ViewBag.PF, uwid = "#=UserName#" }, new { #class = "k-button k-button-icontext" }).ToHtmlString());
Try something like this
VB code:
.ClientTemplate(Html.ActionLink("Roles", "UserRolesManage", New With {.UserId = "#=UserId#", .UserLogin = "#=UserLogin#"}).ToHtmlString()
C# code:
.ClientTemplate(#Html.ActionLink("Roles", "UserRolesManage", New {UserId = "#=UserId#", UserLogin = "#=UserLogin#"}).ToHtmlString()
in my kendo grid, I have 3 columns, balance, adjustment, and adjustment balance. adjustment balance is the total of balance and adjustment. it will be calculated. If I make a change to adjustment field. adjustment balance should automatically changed.
I am binding save event to grid.
$("#DebtGrid").data("kendoGrid").bind("save", onDebtGridEditComplete);
function onDebtGridEditComplete(e) {
debugger;
var grid = $('#NonrecourseDebtGrid').data().kendoGrid;
var dataItem = e.model;
e.model.set('TaxAdjustments', e.values.TaxAdjustments);
var newBalance = getAdjBalance(dataItem.TaxBalance, e.values.TaxAdjustments);
e.model.set('TaxAdjustmentBalance', newBalance);
//grid.refresh();
}
I debugged the following function, I see the newBalance is calcualted and after I set the textadjustmentbalance. I checked the e.model, nothing changed. it still has the old value there.
e.model.set('TaxAdjustmentBalance', newBalance);
here's my grid.
#(Html.Kendo().Grid<LiabilityVM>()
.Name("DebtGrid")
.HtmlAttributes(new { style = "height: 300px;" })
.Columns(columns =>
{
columns.Bound(i => i.Id).Visible(false);
columns.Bound(i => i.AccountId).Visible(false);
columns.Bound(i => i.AccountNumber)
.Title("Account #")
.HtmlAttributes(new { nowrap = "nowrap" })
.Width(70);
columns.Bound(i => i.TaxBalance)
.Title("Balance")
.HtmlAttributes(textAlign)
.Width(70);
columns.Bound(i => i.TaxAdjustments)
.Title("Adjustments")
.EditorTemplateName("AmountEditor")
.HtmlAttributes(textAlign)
.Width(70)
.ClientFooterTemplate("<span><b> Total: </b></span>")
.FooterHtmlAttributes(textAlign);
columns.Bound(i => i.TaxAdjustmentBalance)
.Title("Adj. Balance")
.ClientTemplate("<span href='\\#' style='white-space:nowrap'>#= TaxAdjustmentBalance #</span>")
.HtmlAttributes(textAlign)
.Width(70)
.ClientFooterTemplate("#= formatAmount(getTotalAdjBalance('NonrecourseDebtGrid'), '{0:c0}') #").FooterHtmlAttributes(textAlign);
columns.Bound(i => i.IsSuppressed)
.Title("Suppress")
.ClientTemplate("#= showCheckBox(IsSuppressed,Source, Id) #")
.Width(50)
.Sortable(false)
.Filterable(false);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(grid => grid.Ajax()
.Batch(true)
.Model(model => {
model.Id(i => i.Id);
model.Field(p => p.AccountNumber).Editable(false);
model.Field(p => p.TaxBalance).Editable(false);
model.Field(p => p.TaxAdjustmentBalance).Editable(false);
})
.ServerOperation(true)
.Create(create => create.Action("Update", "test", parameters))
.Read(read => read.Action("Get", "test", parameters))
.Update(update => update.Action("Update", "test", parameters))
.Aggregates(aggregates =>
{
aggregates.Add(p => p.TaxAdjustmentBalance).Sum();
})
)
.Sortable()
.Filterable()
.Selectable(s => s.Mode(GridSelectionMode.Single))
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.ColumnMenu()
.Scrollable()
)
This is happening because you have set the field to be non-editable.
model.Field(p => p.TaxAdjustmentBalance).Editable(false);
You can try to make the field editable and create custom editor which just displays the value, so the users cant edit it.
here's my kendo grid using aspl.net mvc wrapper. the problem is when you do a batch inline editing. and click on save.
.Create(create => create.Action("UpdateLiabilities", "Liability", parameters))
will be triggered and saved all the changes into the database. now I need to added a callback function to show an account successfully added message. I am not sure how to add this callback function.
#(Html.Kendo().Grid<LiabilityVM>()
.Name("QualifiedNonrecourseDebtGrid")
.HtmlAttributes(new { style = "height: 300px;" })
.Columns(columns =>
{
columns.Bound(i => i.Id).Visible(false);
columns.Bound(i => i.AccountId).Visible(false);
columns.Bound(i => i.AccountNumber)
.Title("Account #")
.ClientTemplate("<span style='white-space:nowrap'> #= AccountNumber # </span>")
.HtmlAttributes(new { nowrap = "nowrap" })
.Width(70);
columns.Bound(i => i.Description)
.Title("Description")
.ClientTemplate("<span href='\\#' title='#= getEncodedValueOrDefault(Description, '')#' style='white-space:nowrap'>#= getHtmlEncode(Description, '') #</span>")
.HtmlAttributes(new { nowrap = "nowrap" })
.Width(120);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(grid => grid.Ajax()
.Batch(true)
.Model(model => {
model.Id(i => i.Id);
model.Field(p => p.AccountNumber).Editable(false);
})
.ServerOperation(true).Group(groups => groups.Add(p => p.Source))
.Create(create => create.Action("UpdateLiabilities", "Liability", parameters))
.Read(read => read.Action("GetLiabilities", "Liability", parameters))
.Update(update => update.Action("UpdateLiabilities", "Liability", parameters))
.Aggregates(aggregates =>
{
aggregates.Add(p => p.TaxAdjustmentBalance).Sum();
})
)
.Sortable()
.Filterable()
.Selectable(s => s.Mode(GridSelectionMode.Single))
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.ColumnMenu()
.Scrollable()
)
There is a special event for this called sync.
In your case it should be something like this:
.DataSource(grid => grid.Ajax().Events(ev=>ev.Sync("theNameOfTHeCallBackFUnction")))
in your UpdateLiabilities method
return jsonp instead of json ( JavaScriptResult) as
const string alertMessage = "created";
string aMessage = string.Format("alert('{0}');", alertMessage);
var returned = new JavaScriptResult { Script = aMessage };
return returned;