Note that there are some explanatory texts on larger screens.

plurals
  1. POKendo ui export csv
    text
    copied!<p>Currently the export to csv work fine and currently export all. Is there anyway i can put filter to export only based on the row selected?. Please advise. OnChange event it will pass in the ID to the controller. But I just need to find out if button Export click, it also hit the OnChange event</p> <p>View:</p> <pre><code> @(Html.Kendo().Grid&lt;HAp.Models.SessionModel&gt;() .Name("List") .HtmlAttributes(new { @Style = "align:center; font-size:10.5px; length:100%" }) .Columns(columns =&gt; { columns.Bound(p =&gt; p.ReftID).Visible(false); columns.Bound(p =&gt; p.CreateDate); columns.Bound(p =&gt; p.CreateBy) columns.Bound(p =&gt; p.Description); }) .ToolBar(toolbar =&gt; toolbar.Create()) .ToolBar(toolBar =&gt; toolBar.Custom() .Text("Export To CSV") .HtmlAttributes(new { id = "export" }) .Url(Url.Action("Export", "Index", new { page = 1, pageSize = "~", filter = "~", sort = "~" })) ) .Editable(editable =&gt; editable.Mode(GridEditMode.InLine)) .Selectable(s =&gt; s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single)) .Pageable() .Scrollable() .DataSource(dataSource =&gt; dataSource .Ajax()//bind with Ajax instead server bind .PageSize(10) .ServerOperation(true) .Model(model =&gt; model.Id(p =&gt; p.ReftID)) . .Events(ev =&gt; ev.DataBound("onDataBound").Change("onChange")) ) function onChange(e) { var grid = $('#List').data('kendoGrid'); //get a reference to the grid data var record = grid.dataItem(grid.select()); //get a reference to the currently selected row var GuidID = record.ReftID; $.ajax({ type: 'POST', url: "@(Url.Content("~/Test/Export/"))", data: { "ID": GuidID } }); } function onDataBound(e) { var grid = $('#List').data('kendoGrid'); // ask the parameterMap to create the request object for you var requestObject = (new kendo.data.transports["aspnetmvc-server"]({ prefix: "" })) .options.parameterMap({ page: grid.dataSource.page(), sort: grid.dataSource.sort(), filter: grid.dataSource.filter() }); // Get the export link as jQuery object var $exportLink = $('#export'); // Get its 'href' attribute - the URL where it would navigate to var href = $exportLink.attr('href'); // Update the 'page' parameter with the grid's current page href = href.replace(/page=([^&amp;]*)/, 'page=' + requestObject.page || '~'); // Update the 'sort' parameter with the grid's current sort descriptor href = href.replace(/sort=([^&amp;]*)/, 'sort=' + requestObject.sort || '~'); // Update the 'pageSize' parameter with the grid's current pageSize href = href.replace(/pageSize=([^&amp;]*)/, 'pageSize=' + grid.dataSource._pageSize); //update filter descriptor with the filters applied href = href.replace(/filter=([^&amp;]*)/, 'filter=' + (requestObject.filter || '~')); // Update the 'href' attribute $exportLink.attr('href', href); } Controller: public FileResult Export([DataSourceRequest]DataSourceRequest request) { IEnumerable list = db.GetAll(); MemoryStream output = new MemoryStream(); StreamWriter writer = new StreamWriter(output, Encoding.UTF8); writer.Write("Ref ID,"); writer.Write("Create Date,"); writer.Write("Create By,"); writer.Write("List Description,"); writer.Write("List Status,"); writer.WriteLine(); foreach (vwListDetail lists in list) { writer.Write(lists .RefID); writer.Write(","); writer.Write(lists .CreateDate.Value.ToShortDateString()); writer.Write(","); writer.Write(lists .CreatedBy); writer.Write(","); writer.Write(lists .ListDescription); writer.Write(","); writer.WriteLine(); } writer.Flush(); output.Position = 0; return File(output, "text/comma-separated-values", "List.csv"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload