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

datasource - specify columns?

8 Answers 621 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 11 Nov 2015, 04:54 PM
Hi. Is there a way to specify which fields are shown in the spreadsheet when binding to a datasource?  I tried excluding a field in schema.model.fields but the spreadsheet still displays all the fields as columns.  Also, is there a way to specify the order that the columns appear?

8 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 13 Nov 2015, 04:56 PM

Hello Kevin,

Currently, this is not possible via the initial configuration. However, it is possible when using setDataSource method of the Sheet. Similar to the following:

var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");         
 
var sheet = spreadsheet.activeSheet();
 
sheet.setDataSource(dataSource, [
  { field: "ProductID", title: "Product ID" },
  { field: "ProductName", title: "Product Name" },
  { field: "UnitPrice", title: "Unit Price" }
]);


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeff
Top achievements
Rank 1
answered on 09 May 2016, 06:56 PM

Where would this code be placed on the page as I am having the same issue.

 

I tried the sheet.RequestEnd which works as you described when the page loads but as soon as I start to try and edit any of the cells in the spreadsheet the page freezes with a long running script error. If I comment out the code and just load the whole table everything works fine

 

thanks

Jeff Murtari

0
Rosen
Telerik team
answered on 10 May 2016, 06:35 AM

Hello Jeff,

The code in question should be executed at the point where it is appropriate to set the DataSource instance for your specific scenario. For example if you want to set the DataSource during initial loading you could use a document ready to do so.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Rosen
Telerik team
answered on 10 May 2016, 06:39 AM

Hello Jeff,

Just to add about the approach you have tried. You should not use requestEnd to change the DataSource instance as this could result in an endless loop,. which I suspect is the behavior you are experiencing.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeff
Top achievements
Rank 1
answered on 10 May 2016, 01:45 PM

Rosen thanks for the quick reply. Would you have a quick example as I am having some issues with the document ready.

I have the datasource set in the sheet .Read command but am trying to limit the columns displayed. The trouble I seem to be having with the documentready is that the datasource is set at the .Sheet level and not the spreadsheet control level

 

thanks

jeff

 

0
Jeff
Top achievements
Rank 1
answered on 10 May 2016, 04:07 PM

Rosen I have gotten the document ready script to work so thank you for pointing me in the right direction. Now just having an issue when I try to update a date field in the spreadsheet but will open another ticket

 

thanks again

0
Sandeep
Top achievements
Rank 1
answered on 17 Jul 2018, 11:32 AM

I referred your above code while using setDataSource method. But the field column names looks static or fixed here. For me I have the column names generated dynamically and it may vary in number. I will have the field and title values but how can I use the loop to iterate through the variables to set  the respective field and title values in above code?

Please let em know.

0
Dimitar
Telerik team
answered on 19 Jul 2018, 08:18 AM
Hello Sandeep,

You could retrieve the dynamically generated columns by the following code:
<script>
  var sheet = $("#spreadsheet").data("kendoSpreadsheet").activeSheet();
                        
  var columns = sheet.dataSourceBinder.columns;
  console.log(columns);
</script>

Check out the following Dojo example, where after the SpreadSheet data is bound, the columns of the sheet are being logged in the browser console. You should be able to then iterate over them and process them further depending on the project requirements.

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
Kevin
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jeff
Top achievements
Rank 1
Sandeep
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or