Update Datasource After Import

9 posts, 0 answers
  1. Marc
    Marc avatar
    138 posts
    Member since:
    Sep 2016

    Posted 06 Jan Link to this post

    Hi

    I have a spreadsheet component, with a datasource. I am exporting a dataset from the spreadsheet, changing it in Excel, and then reimporting it. After I import data, if the imported data has more records than the current dataset, the dataSource is not updated so when I save nothing happens.

    In my save, I use dataSource.hasChanges to check if we have changes in the dataset. This is true, even if I have only added a record. However - dataSource.data().length is still the original size. I have tried with dataSource.sync(). Is there something I am missing?

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1867 posts

    Posted 10 Jan Link to this post

    Hello Marc,

    I am not sure that I understand the problem you are facing. Could you please replicate the described behavior in a simple dojo? A sample list of steps and explanation of the actual behavior and expected behavior will be very helpful. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Marc
    Marc avatar
    138 posts
    Member since:
    Sep 2016

    Posted 10 Jan in reply to Boyan Dimitrov Link to this post

    Hi Boyan,

    I have a spreadsheet with dataSource component. When the user goes to the screen, they import some data into the spreadsheet (using the spreadSheet.fromFile method). They then press a save button. In the function of the save button, I call the method dataSource.data().length, but it is empty. Does that make sense?

  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1867 posts

    Posted 12 Jan Link to this post

    Hello Marc,

    Thank you for the clarification. 

    Indeed this is rather expected behavior since the fromFile method of the Kendo UI SpreadSheet does not create a DataSource for the sheet or update the existing one (if a DataSource is set initially for the sheet).

    In order to change the data of the DataSource of specific sheet you can use the data method of Kendo UI DataSource or the setDataSource method of the sheet. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Marc
    Marc avatar
    138 posts
    Member since:
    Sep 2016

    Posted 12 Jan in reply to Boyan Dimitrov Link to this post

    Hi Boyan,

    Thanks for the information! I can understand why it behaves like this. Is there any way to update the datasource with the new data?

    Ie, after spreadsheet.fromFile is there a parameter that gives me the new data which is derived from the imported file? Something to set the data to as below:

    spreadSheet.fromFile(importFileElement.files[0]).then(function () {

    mydataSource.data(I need a variable here?);

    })

    Thanks!

    Marc

  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1867 posts

    Posted 16 Jan Link to this post

    Hello Marc,

    I am afraid that there is no variable in the promise resolve function with the new data. Furthermore, the approach from your last response will populate the SpreadSheet (fromFile method) and then populate the DataSource of the DataSource. The initial operation of populating the SpreadSheet from file will be unnecessary. Especially that in the promise resolve there is no data one additional operation will be required in order to export to JSON the SpreadSheet after populating from file. This will help you to have data from the excel file as JSON and pass it to the data method of the DataSource. 

    My suggestion is to simply find a way to extract data from the excel file to JSON array and pass it directly to the DataSource of the Sheet. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Marc
    Marc avatar
    138 posts
    Member since:
    Sep 2016

    Posted 16 Jan in reply to Boyan Dimitrov Link to this post

    Hi Boyan,

    Thanks for the information. So essentially the export/import functionality you have (fromFile etc methods) are only for displaying data inside the spreadsheet and cannot be used with the transport layer to save the data?

  8. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1867 posts

    Posted 18 Jan Link to this post

    Hello Marc,

    Unfortunately the fromFile does not create/update a DataSource for a sheet. Indeed its purpose is to display data and it can not be used with the transport layer out of the box. As I mentioned a solution would be extract JSON data from the excel file and pass it to the DataSource of the SpreadSheet. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Marc
    Marc avatar
    138 posts
    Member since:
    Sep 2016

    Posted 18 Jan in reply to Boyan Dimitrov Link to this post

    Hi Boyan,

    Thanks again for the help. I managed to work around this by importing the data into the spreadsheet using the built in method, and then I use the .range of the spreadsheet to select all the values, create my JS objects and then used dataSource.data(myArrayOfObjects) to sync the dataSource.

    Thanks again!

Back to Top