Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Exporting Grid to Excel with % Width

$
0
0

Hi Dimiter,

It's me again :)

I am trying to do export to excel. I have already toolbar template on a grid for new record which is working fine and i want to add one more toolbar for export to excel button and it is not displaying. When i remove new record button, it is displaying properly but when i keep both export to excel button is not displaying.

After displaying too, my export to excel button is not working too. it is not doing anything. Did i miss anything else?

<divclass="container-fluid">
    <br/><br/><br/>
    <divclass="row">
        <divclass="col-xs-18 col-md-12">
            @(Html.Kendo().Grid<BHEBS.Areas.Admin.Models.ContractorModel.contractor>()
        .Name("grid")
        .Columns(columns =>
        {
            //columns.Bound(p => p.Id).Filterable(false).Width(50);
            columns.Bound(p => p.ContractorName);
            columns.Bound(p => p.ContractorType).Title("Type").Width(80);
            columns.Bound(p => p.BHSISNum).Width(180); ;
            columns.Bound(p => p.ContractorIsAlsoRegion).Width(110).Title("Is Region").ClientTemplate("<inputtype='checkbox'disabled='disabled'#= ContractorIsAlsoRegion ? checked='checked': '' # class='chkbx'/>").HtmlAttributes(new { style = "text-align: center" });
            columns.Bound(p => p.AddressBkNum).Width(160);
            columns.Bound(p => p.StartDate).Format("{0:MM/dd/yyyy}").Width(140);
            columns.Bound(p => p.EndDate).Format("{0:MM/dd/yyyy}").Width(140); ;
            columns.Bound(p => p.ISAT).Width(100);
            columns.Bound(p => p.MHS).Width(100);
            columns.Bound(p => p.ParentName).Width(170); ;
            columns.Command(command =>
            {
                command.Custom("Edit").SendDataKeys(true).Click("editClick");
                command.Custom("View").SendDataKeys(true).Click("viewClick");
                //command.Custom("Delete").SendDataKeys(true).Click("deleteClick");
            }).Width(160);
        })
               
           .Events(e => e.DataBound("onDataBound"))
                 .Pageable(pageable => pageable
                    .Refresh(true)
                    .PageSizes(true)
                    .ButtonCount(5))
        .Sortable()
                 .Scrollable()
        .Filterable()
        .Selectable()
                 
                .HtmlAttributes(new { style = "height:636px;" })
        .DataSource(dataSource => dataSource
        .Ajax()
 
                .Read(read => read.Action("Contractors_Read", "Contractor"))
        )
                .ToolBar(toolbar =>
        {
            toolbar.Template(@<text>
                <divclass="toolbar">
                    <inputtype="button"title="New Record"value="New Record"onclick='OnCreate()'class="k-button k-button-icontext k-grid-add k-primary"/>
                    @*   <aclass="k-button k-button-icontext k-grid-add k-primary"href="/Admin/Contractor/Create">New Record</a>*@
 
                </div>
            </text>);
            toolbar.Excel().HtmlAttributes(new { @class = "pull-right" }).Text(" Export to Excel");
        })
                .Excel(excel => excel
                        .FileName("Kendo UI Grid Export.xlsx")
                        .Filterable(true)
                        .ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
                    )
            )
        </div>
    </div>
</div>
 
Controller Method :
 
    [HttpPost]
        public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
        {
            var fileContents = Convert.FromBase64String(base64);
 
            return File(fileContents, contentType, fileName);
        }

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>