This is a migrated thread and some comments may be shown as answers.

Toolbar destroyed

1 Answer 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 12 Feb 2015, 10:12 AM

Hi,

I'm using a grid wich keep state without problem
My only problem is that when the grid is rebuild, my toolbar ( export to excell ) has disapeard.

@(Html.Kendo().Grid<UserCustomizedViewModel>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
aggregates.Add(p => p.Origin_Code).Count();
})
.Read(read => read.Action("UserCustomizedRead", "Rdr")
.Data("asco.rdrReadData"))
.Model(model => model.Id(rdr => rdr.Id))
.PageSize(50)
.Sort(sort => sort.Add(model => model.RdrNumber).Descending())
.Events(events =>
{
events.Error("onGridDataSourceError");
events.Change("onGridDataSourceChange");
}))
.Events(events => events.DataBound("onGridDataBound"))
.Columns(columns =>
{
columns.Bound(model => model.Origin_Code)
.Title(Global.ColumnOrigin)
.ClientTemplate("<span class='tooltips' data-placement='top' title='#= Origin_Value_English #'>#= Origin_Code # </span>")
.Visible(currentCulture == Cultures.En)
.Width(20)
.ClientGroupFooterTemplate("Count: #=count#");
columns.Bound(model => model.Origin_Code)
.Title(Global.ColumnOrigin)
.ClientTemplate("<span class='tooltips' data-placement='top' title='#= Origin_Value_French #'>#= Origin_Code # </span>")
.Visible(currentCulture == Cultures.Fr)
.Width(20)
.ClientGroupFooterTemplate("Count: #=count#");
columns.Bound(model => model.Origin_Code)
.Title(Global.ColumnOrigin)
.ClientTemplate("<span class='tooltips' data-placement='top' title='#= Origin_Value_German #'>#= Origin_Code # </span>")
.Visible(currentCulture == Cultures.De)
.Width(20)
.ClientGroupFooterTemplate("Count: #=count#");
columns.Bound(model => model.Origin_Code)
.Title(Global.ColumnOrigin)
.ClientTemplate("<span class='tooltips' data-placement='top' title='#= Origin_Value_Dutch #'>#= Origin_Code # </span>")
.Visible(currentCulture == Cultures.Nl)
.Width(20)
.ClientGroupFooterTemplate("Count: #=count#");
columns.Bound(model => model.RdrNumber)
.Title(Global.ColumnRdrNumber)
.ClientTemplate(Html.ActionLink("#= RdrNumber #", "Edit", new { id = "id" }).ToHtmlString().Replace("id", "#=Id#"))
.Width(70);
columns.Bound(model => model.RdrStatus_Value_English)
.Title(Global.ColumnRdrStatusType)
.Visible(currentCulture == Cultures.En)
.Width(70);
columns.Bound(model => model.RdrStatus_Value_German)
.Title(Global.ColumnRdrStatusType)
.Visible(currentCulture == Cultures.De)
.Width(70);
columns.Bound(model => model.RdrStatus_Value_French)
.Title(Global.ColumnRdrStatusType)
.Visible(currentCulture == Cultures.Fr)
.Width(70);
columns.Bound(model => model.RdrStatus_Value_Dutch)
.Title(Global.ColumnRdrStatusType)
.Visible(currentCulture == Cultures.Nl)
.Width(70);
columns.Bound(model => model.CreatedOn)
.Title(Global.ColumnCreatedOn)
.Format("{0:dd/MM/yyyy}")
.Width(100);
columns.Bound(model => model.CreatedByText)
.Title(Global.ColumnCreatedBy)
.Width(150);

})
.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.FileName("Kendo UI Grid Export.xlsx")
.Filterable(true)
.AllPages(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Rdr"))
)
.Reorderable(r => r.Columns(true))
.Resizable(r => r.Columns(true))
.Groupable()
.ColumnMenu()
.Pageable(pager => pager
.Refresh(true)
.PageSizes(new[] { 50,100, 200, 500, 1000, 3000 })
.Messages(messages =>
{
messages.Refresh(Global.GridPagerClickToRefresh);
messages.ItemsPerPage(Global.GridPagerItemsPerPage);
messages.Of(Global.GridPagerOf);
messages.Next(Global.GridPagerNext);
messages.Last(Global.GridPagerLast);
messages.First(Global.GridPagerFirst);
messages.Previous(Global.GridPagerPrevious);
messages.Page(Global.GridPagerPage);
messages.Empty(Global.GridPagerEmpty);
messages.Display(Global.GridPagerDisplay);
}))
.Filterable(filter =>
{
filter.Extra(true);
filter.Messages(messages =>
{
messages.And(Global.GridFilterAnd);
messages.Clear(Global.GridFilterClear);
messages.Filter(Global.GridFilterFilter);
messages.Info(Global.GridFilterInfo);
messages.IsFalse(Global.GridFilterIsFalse);
messages.IsTrue(Global.GridFilterIsTrue);
messages.Or(Global.GridFilterOr);
messages.SelectValue(Global.GridFilterSelectedValue);
});
filter.Operators(oper => oper.ForString(messages =>
{
messages.Clear();
messages.IsEqualTo(Global.GridFilterIsEqualTo);
messages.Contains(Global.GridFilterContains);
messages.StartsWith(Global.GridFilterStartsWith);
}));
})
//.Sortable(sortable => sortable.AllowUnsort(false))
)

Here is the code that load the state of my grid

var grid = $("#grid").data("kendoGrid");
//var dataSource = grid.dataSource;
var url = $("#LoadGridState").data('request-url');
var GridName = $("#SaveGridState").data('gridname');
$.ajax({
url: url,
type: 'POST',
async: false,
//cache: false,
data: {
GridName: GridName
},
success: function (state) {
try{
state = JSON.parse(state);
var options = grid.options;
options.columns = state.columns;
options.dataSource.page = state.page;
options.dataSource.pageSize = state.pageSize;
options.dataSource.sort = state.sort;
options.dataSource.filter = state.filter;
options.dataSource.group = state.group;
grid.destroy();
$("#grid")
.empty()
.kendoGrid(options);

}
catch (e) {
}

},
error: function (request, status, errorThrown) {
window.alerts.error(errorThrown);
}
});

thanks for your help

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 16 Feb 2015, 08:26 AM
Hello Michel,

A more appropriate way to set the Grid state will be by using the setOption method. As mentioned in the description of the setOptions method, when using the ASP.NET MVC wrappers, the Toolbar template is rendered on the server, thus it cannot be recreated on the client. A way to workaround this limitation by manually assigning the toolbar template prior the widget re-creation is demonstrated in this hot-to article/project. Here is the project for the article.

Regards,
Rosen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Michel
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or