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

Spreadsheet render event

3 Answers 140 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 18 Jan 2018, 12:59 PM

When I put code in the onRender(e) event, the OnRender event keeps firing causing stack overflow errors.

What I've succeeded in doing is:
loading my model (Columns A-N) 

 

What I'd like to do after the model has loaded is:

1. Disable columns A:B

2. Add formulas in Columns (O-Q)

 

How do I do this?

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 22 Jan 2018, 02:57 PM
Hello Bruce,

I apologize for the delayed response.

Disabling cells can be achieved by retrieving the specified range, which we would like to disable and then using the Spreadsheet Range's enable() method. This is demonstrated in the following Spreadsheet demo:


For applying a formula to a cell, the Spreadsheet Range's formula() method can be used. Check out the following Dojo example, where you can see the method in action:


I hope this helps. Should you have any additional questions, please let me know.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Bruce
Top achievements
Rank 1
answered on 22 Jan 2018, 06:03 PM
Thank you for the answer BUT I was asking specifically how to do this after the spreadsheet has rendered i.e. the render event. Now I'm using a button because I get a stack overflow error after binding an MVC model against the spreadsheet.

Another question in the same vein is how to add formulas to a model bound spreadsheet and then add headings to them. When I do this via code it corrupts my model (please see attached example)
0
Dimitar
Telerik team
answered on 24 Jan 2018, 01:41 PM
Hello Bruce,

I am attaching and ASP.NET MVC solution, where a similar scenario to the one described is demonstrated (Disabling column cells and adding formula after the initialization of the Spreadsheet).

Indeed you are correct that the render event is not suitable to be used in this case. In order to set disabled cells and add custom formulas after the Spreadsheet is completely rendered and the data is loaded, the DataSource's requestEnd event can be used:
<script>
function onRequestEnd (e) {
if (e.type === "read") {
setTimeout(function () {
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
var sheet = spreadsheet.activeSheet();
 
var data = sheet.toJSON();
var totalRowsCount = data.rows.length;
               
var range = sheet.range("A1");
range.value("Employee Name");
 
var rowsCount = spreadsheet.options.rows;
sheet.range("A1:A1" + rowsCount).enable(false);
 
var range = sheet.range("F1");
range.value("Total Year");
              
var range = sheet.range("F2:F" + totalRowsCount);
range.formula("SUM(B2:E2");
}, 0);               
}        
}
</script>

You will notice that the entire coolumn cells that contain value can be disabled by using the following approach:
var rowsCount = spreadsheet.options.rows;
sheet.range("A1:A1" + rowsCount).enable(false);

Concerning the model changes, it is expected that when changing the model data (e.g field title), that the dirty flag of the model will be set to true. Can you elaborate a bit more on what are your concerns regarding this behavior in the specific use case?

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
Bruce
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or