Auto-Fit column width when exporting to excel using Format="Xlsx" I'd really like to have the columns automatically adjust to fit the width of the content.
I have a RadGrid with around 150 columns and a few hundred rows. Currently, I'm looping over them and setting their widths with the resizeColumn function. Unfortunately, it's triggering a recalculation of the layout every time I call this function, so the total page load time can be in the minutes. Oddly, much of the time was spent on the line: e.style.width=e.offsetWidth-d+"px"; Chrome's developer tools helpfully pointed me at Forced Reflow. Apparently, when a width is set, initially no extra work is done. When another width is requested, the previous width may have changed it, so the whole layout gets recalculated. The feature I'd like to request is a function to set column widths in bulk (accepting anything like an array or a dictionary would be fine) that doesn't trigger this recalculation mid-function.
Grid in BatchEdit mode must be one of the most useful features in some serious industry-level web applications. It comes quite naturally, that the data in the grid must be often extensively validated, and in many cases the client side validation is simply not enough. In our case, we had to use BatchEditing mode and we had to validate user-entered values serverside (due to complex rules, external data to validation against in real time and safety/security of the validation itself).
Documentation states that BatchEdit does not support ServerSide validation. This makes BatchEdit mode mostly useless for some serious use, which is a pitty. But how much is needed to do so? The only thing we need is, when processing RadGrid_BatchEditCommand, to send the unsaved changes back to the client (overwrite the old values which would come from the database via NeedDataSource) and mark the changed cells as "EDITED" or "CHANGED", because:
a. We have to make sure, that the unsaved rows from the session variable will always come up, next time the user hits the Save changes button, in the BatchEditCommand in Hashtable newValues = command.NewValues; This is because only rows, which RadGrid understand as changed by user-client side, will come up in the newValues HashTable. In case that the user changed, in the first server-side roundtrip, rows 1 and 2, rows 1 and 2 would be saved to the session variable and they would be presented to the user, but in the second round user would not change rows 1 and 2 but change only row 3, it would be only row 3 which would come up in RadGrid1_BatchEditCommand the newValues Hashtable, and we would never get previous, still unsaved, changes
b. in case the user goes to the next page of the grid, using paging arrows in the grid, the grid normally warns about unsaved changes and prevents user from going to the next page, if there are any unsaved changes. If our changed rows from the session are not marked as EDITED, the grid would never ask this and would proceed to the next page, losing users changes.
We were fighting to make this work via some session variables, etc, but then Doncho from Telerik support sent us this simple solution. I think many would be happy if you could add it to the next release, so it is supported out of the box. Attaching files from Doncho, which give an ide to the solution
Thank you.
radgrid exporttoexcel and all exports (word, pdf, csv, excel) should be able to export to file on server without the browser also sending the file to the client.
See online demo:
https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx
Steps to reproduce (seen in Chrome and Edge):
- Click the "x" on the 2nd to last record on page 1 to mark it for deletion (Click "OK" at the prompt)
- Click "Add new record" button
Observe:
- the record marked for deletion moves up by one record (but fortunately it appears the correct record will actually get deleted upon Saving)
- a blank new record is creating correctly
If you repeat this procedure but choose a different record for deletion you can see it is functioning correctly.
I am seeing the same behaviour in my own project.
For Bug Report : Note: We are using MM/dd/yyyy as Internal Date format to prevent issue while inserting or updating value. Steps to reproduce: When we use dd-MM-yyyy and yyyy-dd-MM Date DisplayFformat for RadDatePicker/RadDateTimePicker control as well as view mode in Radgrid Batch Edit mode it's render behaviour is inconsistent 1. When dd is less than or equal to 12 then while rendering in edit mode Month and Date is interchanged 2. When dd is greather than 12 then while rendering in edit mode Month and Date is rendered correctly.
Currently, the "GridButtonColumn" and "GridEditCommandColumn" columns render only ASP Buttons such as ImageButton, PushButton, LinkButton.
We would like to have the option to Choose Telerik Buttons such as RadButton, RadImageButton as ButtonType for the Columns.
The date pickers default to the year 1999 and do not accept inputs, so you cannot filter GridDateTimeColumn instances through the header context menu or the excel-like filtering. The standard filter item and range filter can still be used instead of context menus, but they are not available with excel-like filtering.
You would get something like (([createddate] >= '01/08/2017,00:00:00') AND ([createddate] <= '14/08/2017,23:59:59')) while you should get something like (([createddate] >= '01/08/2017 00:00:00') AND ([createddate] <= '14/08/2017 23:59:59')) so that the SQL syntax is valid. RadGrid, does not send the FilterExpression to the SqlDataSource, however. It executes the SELECT statement and then filters the resulting data on its own. This works fine. If you will be performing operations yourself, you could use a string operation before passing the filter expression. For example: protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { if (!string.IsNullOrEmpty(this.RadGrid1.MasterTableView.FilterExpression)) { if (this.RadGrid1.MasterTableView.FilterExpression.Contains("createddate")) { this.RadGrid1.MasterTableView.FilterExpression = this.RadGrid1.MasterTableView.FilterExpression.Replace(",", " "); } DataView dv =GetData("select * from [myTable] where ", this.RadGrid1.MasterTableView.FilterExpression); //where you would need to have something like (([createddate] >= '01/08/2017 00:00:00') AND ([createddate] <= '14/08/2017 23:59:59')) this.RadGrid1.DataSource = dv; } } Note that implementing such a change may break existing code that relies on the current syntax that contains the comma.
The FooterAggregateFormatString functionality of the Grid does not affect the Aggregates values format in a client-bound Grid. Code to reproduce: <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" ClientDataSourceID="RadClientDataSource1" AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="true" ShowFooter="true"> <MasterTableView ClientDataKeyNames="CustomerID" EditMode="Batch" CommandItemDisplay="Top" BatchEditingSettings-HighlightDeletedRows="true"> <Columns> <telerik:GridBoundColumn DataField="CustomerID" HeaderText="Customer ID" Aggregate="Count" FooterAggregateFormatString="No currency sign here: {0:C}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company Name" ColumnEditorID="GridTextBoxEditor"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name" ColumnEditorID="GridTextBoxEditor"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="Contact Title" ColumnEditorID="GridTextBoxEditor"> </telerik:GridBoundColumn> <telerik:GridClientDeleteColumn HeaderText="Delete"> <HeaderStyle Width="70px" /> </telerik:GridClientDeleteColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnUserAction="UserAction" /> </ClientSettings> </telerik:RadGrid>
Please add a setting for the Grid in batch edit mode to enable prompting to save changes. The prompt should occur when navigating away from the page, when paging, when filtering, when refreshing, or any other action that would cause loss of changes without a save. For details on how I implemented this manually, please see ticket 933229.
<telerik:RadAjaxPanel runat="server" ID="panel" LoadingPanelID="RadAjaxLoadingPanel1" RenderMode="Inline" EnableAJAX="true">
<div class="row">
<asp:Button runat="server" ID="btnLoad" Text="Load Data" OnClick="btnLoad_Click" />
</div>
<telerik:RadGrid runat="server" ID="radGrid" CssClass="radgrid" Skin="Bootstrap"
ClientSettings-Scrolling-AllowScroll="true"
ClientSettings-Scrolling-ScrollHeight="800"
ClientSettings-Scrolling-UseStaticHeaders="true"
ClientSettings-EnableAlternatingItems="false"
HeaderStyle-Wrap="false" AllowPaging="true" PageSize="50"
ItemStyle-Wrap="false" AllowSorting="true"
OnNeedDataSource="radGrid_NeedDataSource" AllowMultiRowSelection="false"
HeaderStyle-BackColor="White">
<ClientSettings>
<Selecting AllowRowSelect="true" />
</ClientSettings>
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn UniqueName="colEdit" AllowFiltering="false" Exportable="false">
<ItemTemplate>
<asp:LinkButton CssClass="link-button" runat="server" ID="btnEdit">Edit</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="colDelete" AllowFiltering="false" Exportable="false">
<ItemTemplate>
<asp:LinkButton CssClass="link-button" ID="btnDelete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
radGrid.Visible = false;
}
}
protected void btnLoad_Click(object sender, EventArgs e)
{
radGrid.Visible = true;
radGrid.Rebind();
}
protected void radGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
var grid = sender as RadGrid;
grid.DataSource = LoadData();
}
private DataTable LoadData()
{
DataTable tbl = new DataTable();
tbl.Columns.Add(new DataColumn("ADFAFD", typeof(string)));
tbl.Columns.Add(new DataColumn("ADFADFADF", typeof(string)));
tbl.Columns.Add(new DataColumn("ADFADFADFADFASDF", typeof(string)));
tbl.Columns.Add(new DataColumn("HGDH", typeof(string)));
tbl.Columns.Add(new DataColumn("ADFADF ADFADFADF", typeof(string)));
tbl.Columns.Add(new DataColumn("ADF ADSFADF", typeof(string)));
tbl.Columns.Add(new DataColumn("FKHDGJHFGJH", typeof(string)));
tbl.Columns.Add(new DataColumn("SHFSFHSGH", typeof(string)));
tbl.Columns.Add(new DataColumn("ADF ASDFASDF ASDFADSF", typeof(string)));
tbl.Rows.Add(new object[] { "ADFADF", "ASDFADFAFD", "ADFADF", "ADFADFADF ADFADFADFADF ADFADF ADFADFADF ADFADFADFADF ADFADF", "ADFADF", "ASDFADFAFD", "ADFADF", "ADFADFADF ADFADFADFADF ADFADF"});
tbl.Rows.Add(new object[] { "ADFADF", "ASDFADFAFD", "ADFADF", "ADFADFADF ADFADFADFADF ADFADF", "ADFADF", "ASDFADFAFD", "ADFADF", "ADFADFADF ADFADFADFADF ADFADF"});
return tbl;
}