Hello, I am trying to make a function that can resize my spreadsheet sheet dynamically based on the data, which is load on the sheet.
I know that the Spreadsheet has a function called "resize". I pass the numbers of columns and rows with a ViewBag, from the controller to the View on JS.
Controller:
public ActionResult Menus_Read([DataSourceRequest] DataSourceRequest request)
{
try
{
List<MenuViewModel> menus = db.GetMenus();
DataSourceResult result = menus.ToDataSourceResult(request);
ViewBag.RowCount = menus.Count;
ViewBag.ColumnCount = typeof(MenuViewModel).GetProperties().Length;
return Json(result, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
ModelState.AddModelError(string.Empty, ex.Message);
return Json(new[] { new object() }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); ;
}
}
JS:
$(document).ready(function() {
var rowCount = @(ViewBag.RowCount);
var columnCount = @(ViewBag.ColumnCount);
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
var sheet = spreadsheet.activeSheet();
sheet.resize(rowCount, columnCount);
});
To use the ViewBag content for the view I first need to get the data, to check the count of the columns and rows. Maybe this could be my problem, the timing.
Has anyone had a similar problem or can help me?