I am working on an MVC 4 application and I have used a Kendo UI grid on my view. This view has a command column which displays button. On click of this button, I should display a kendo window (popup) which displays a partial view.On clicking 'Close' button on this window, I should once again return back to the grid and the grid should refresh.
Now I have 2 issues with this,
Once I click the button on grid, it displays the window only
once.i.e. if it close the window and again try to click the button on
grid, none of the button responds!
After I click the close button on the window, though the window
closes, but the grid dows not refresh. Instead the entire page
refreshes.
I have used the below code,
#(Html.Kendo()
.Grid(Model)
.Name("DefectGrid")
.Columns(columns =>
{
columns.Bound(d => d.DefectId).Title("ID").Width("5%");
columns.Bound(d => d.Title).Title("Title").Width("20%");
columns.Bound(d => d.Severity).Title("Severity").Width("10%");
columns.Bound(d => d.Status).Title("Status").Width("10%");
columns.Bound(d => d.Description).Title("Description").Width("20%");
columns.Bound(d => d.LoggedBy).Title("LoggedBy").Width("10%");
columns.Bound(d => d.LoggedOn).Title("LoggedOn").Width("10%");
columns.Command(command => command.Custom("ViewDetails").Click("showDetails"));
})
.Pageable()
.Sortable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
.Scrollable(scr => scr.Height(200))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("LoadDefects", "Home").Data("refreshGrid").Type(HttpVerbs.Get))
.PageSize(20)
.ServerOperation(false)))
#(Html.Kendo()
.Window()
.Name("Details")
.Title("Defect Details")
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(1000)
.Height(600)
.Events(ev => ev.Close("onClose"))
)
<script type="text/x-kendo-template" id="template">
<div id="defectDetails">
</div>
</script>
function showDetails(e) {
// e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var wnd = $("#Details").data("kendoWindow");
var defId = dataItem.DefectId;
var actionURL = '#Url.Action("DefectDetail", "Home")';
wnd.refresh({
url: actionURL,
data: { defectId: defId }
});
wnd.center();
wnd.open();
}
function onClose(e) {
if (!confirm("Are you sure you want to close window?"))
e.preventDefault();
}
Can anyone suggest where I am going wrong and how can I fix the issue!!!
Thanks in advance
Try like this, add script tag and it's working fine.
<script type="text/javascript">
function showDetails(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var wnd = $("#Details").data("kendoWindow");
var defId = dataItem.DefectId;
var actionURL = '#Url.Action("DefectDetail", "Home")';
wnd.refresh({
url: actionURL,
data: { defectId: defId }
});
wnd.center();
wnd.open();
}
</script>
You may refresh the grid by calling dataSource.read() on the grid element
probably you may do in the onClose() event of the window,
$("#DefectGrid").data("kendoGrid").dataSource.read();
Related
I have a dropdown by which I select the category of my data in a Kendo grid in my MVC app.
#(Html.Kendo().DropDownList()
.Name("kind")
.HtmlAttributes(new { style = "width:18%" })
.OptionLabel("Select Category")
.DataTextField("Cat_Title")
.DataValueField("Cat_ID")
.Events(e => e.Change("onChange"))
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Overview_Get_Categories", "Announcements");
});
})
)
I need to save my selected value so if the user return back can load his search. I have the following code for my grid
<div class="box-col">
Save State
Load State
and in js
<script>
$(document).ready( function () {
var grid = $("#grid").data("kendoGrid");
$("#save").click(function (e) {
e.preventDefault();
localStorage["kendo-grid-options"] = kendo.stringify(grid.getOptions());
});
$("#load").click(function (e) {
e.preventDefault();
var options = localStorage["kendo-grid-options"];
if (options) {
grid.setOptions(JSON.parse(options));
}
});
});
How can I save the value from the dropdown? and then reload it?
any idea? Thank you!
Screen
Code
In this screen, we have used kendo treelist. I need to implement autocomplete dropdown in CODE column. How can i do that?
Try this
var ac = Html.Kendo()
.AutoComplete()
.Name("CodeAutoComplete")
.DataSource(ds =>
{
ds.Read(read =>
{
read.Url("youraction");
});
ds.ServerFiltering(true);
});
var treeGrid = Html.Kendo()
.TreeList<YourModel>()
.Name("SomeTreeList")
.Columns(columns =>
{
columns.Add().Field(t => t.YourProperty).Editor(ac.ToHtmlString());
});
I solve my above problem as per given below jquery code.
var input2 = jQuery('<input id="WEIGHT_UOM" value="' + e.model.WEIGHT_UOM + '">');
input2.appendTo($(".k-grid-edit-row").find("[data-container-for='WEIGHT_UOM']"))
//create AutoComplete UI component
$("#WEIGHT_UOM").kendoAutoComplete({
dataTextField: "ProjectDesc",
// template: '${ data.ProjectDesc }' + '<span style="display:none;> ${ data.ProjectDesc }</span>',
select: function (org1) {
var dataItem1 = this.dataItem(org1.item.index());
// model.set("field1", dataItem.field1);
e.model.set("WEIGHT_UOM", dataItem1.ProjectID);
},
dataSource: {
type: "jsonp",
serverFiltering: true,
transport: {
read: "#Url.Action("GetISOUnitAutoComp",
"DashBoard")",
}
}
});
I have got a Telerik MVC grid and I would like to export it as a pdf and hide the column "Test2". I am not able to achieve the desired behavior.
#(Html.Kendo().Grid<Lagerbase.Models.Artikel>()
.Name("ArtikelGrid")
.ToolBar(tools => tools.Pdf())
.Pdf(pdf => pdf
.AllPages()
.AvoidLinks()
.PaperSize("A4")
.Scale(0.8)
.Margin("2cm", "1cm", "1cm", "1cm")
.Landscape()
.RepeatHeaders()
.TemplateId("page-template")
.FileName("Artikel.pdf")
.ProxyURL(Url.Action("Pdf_Export_Save", "Grid"))
)
.Columns(columns =>
{
columns.Bound(o => o.Id).Hidden();
columns.Bound(o => o.Test1);
columns.Bound(o => o.Test2);
})
}
This is what I found for an Excel export. So I adjusted the bind to "pdfExport".
Unfortunately it doesn't work for the function e.sender.saveAsExcel();.
<script type="text/javascript">
$(document).ready(function () {
var exportFlag = false;
$("#ArtikelGrid").data("kendoGrid").bind("pdfExport", function (e) {
if (!exportFlag) {
e.sender.hideColumn(1);
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
e.sender.showColumn(1);
exportFlag = false;
}
});
});
</script>
Does someone know a solution to this?
View this Demo : FUll demo
Source
I created a grid with a custom command:
#(Html.Kendo().Grid<OfficeTracker.ViewModels.OffViewModel>()
.Name("OffGrid")
columns.Command(command =>
{
command.Custom("OfficeLocations").SendDataKeys(true).Click("openOfficeLocations");
}); ...
When the button is clicked, It should open another grid in a pop up window.
Here is the KendoWindow:
#{Html.Kendo().Window().Name("OffDetails")
.Title("Office Details")
.Visible(false)
.Modal(true)
.Draggable(true)
.Visible(false)
.Modal(true)
.Draggable(true)
.Content(#<text> #showGrid(6470) </text>)
}
I created a helper to hold the grid (it sends the officeID to the Controller):
#helper showGrid(int officeID)
{
#(Html.Kendo().Grid<OfficeTracker.ViewModels.LocViewModel>()
.Name("LocGrid")
.Columns(columns =>
{ ...
}
Then this JavaScript function:
function openOfficeLocations(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var officeid = dataItem.OfficeID;
var wnd = $("#OfficeDetails").data("kendoWindow");
//wnd.content(wnd.content(#<text> #showWCGrid(officeid) </text>));
wnd.center().open();
wnd.refresh();
}
My problem is with the "wnd.content" line. If I don't include it, the grid opens when I click on the "OfficeLocations" button, but because I have hard coded the officeid, it always opens the same record. If I include the "wnd.content" line, it throws an error. I don't know if this needs to be formatted a certain way or what the problem is.
I'm not sure if this is the right approach. This is kind of like a detail window, but I need to have two buttons.
I am having a kendo UI Splitter with left pane and right pane. In the left pane I have kendoui Panel bar which consists of links to different reports. Now onclick of any link I am trying to open the report page in right pane by making use of iframe. But for some reason report page is opening in a new window.
Sample Anchor tag from one of the links in Panel bar
<a class="right" target="reportDisplayPane" title="MyTitle" href="reports/params.aspx?rt=Basic Reports&rn=My Report">My Report</a>
MVC View code with Kendo Ui Splitter, Kendo Ui Panel bar and I frame.
#(Html.Kendo().Splitter()
.Name("splitter")
.Orientation(Kendo.Mvc.UI.SplitterOrientation.Horizontal)
.Panes(horizontalPanes =>
{
horizontalPanes.Add()
.Size("20%")
.HtmlAttributes(new { id = "left-pane", style = "height:100%;" })
.Collapsible(true)
.Content(#<div class="pane-content">
<div id="navigation">
#(Html.Kendo().PanelBar()
.Name("panelbar")
.ExpandMode(Kendo.Mvc.UI.PanelBarExpandMode.Multiple)
.HtmlAttributes(new { style = "width:100%;height:100%;" })
.Items(panelbar =>
{
foreach (var category in Model.MyModel.Categories)
{
panelbar.Add().Text(category)
.Items(reports =>
{
foreach (var report in Model.MyModel.Reports)
{
if (report.Category.Equals(category))
{
reports.Add().Text(report.NavigateURL).Encoded(false);
}
}
});
}
})
)
</div>
</div>
);
horizontalPanes.Add()
.Size("80%")
.HtmlAttributes(new { id = "right-pane",style = "height:100%;"})
.Collapsible(false)
.Content(#<div class="pane-content">
<iframe id="reportDisplayPane" ></iframe>
</div>);
})
Please suggest on what might be wrong here.
Achieved it using below.
var onSelect = function (e) {
var iframeUrl = 'reports/maypage.aspx?rt=Myreports&rn=' + e.item.innerText;
$('#reportDisplayPane').attr('src', iframeUrl);
};
var panelBar = $("#panelbar").kendoPanelBar({
select: onSelect
});