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

Bind Dataset Result to Telerik Spreadsheet

1 Answer 198 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Karthik
Top achievements
Rank 1
Karthik asked on 20 Oct 2017, 11:37 AM

Hi,

I have embed the spreadsheet for MVC in my mvc application.I am loading data from database into a dataset and I want to bind the dataset to my spreadsheet. I am not using Entity Framework as my database and column retrieved dynamic and changes each time. Hence i wont be able to create a model for my values. 

Below is my code for loading data to dataset

public ActionResult Products_Load([DataSourceRequest]DataSourceRequest request)
        {
            DataSet ds = HandlerFunctions.GetDynamicSheetData(1, 2);
            var das = ds.Tables[0].AsEnumerable().AsQueryable();
            DataSourceResult result = das.ToDataSourceResult(request);
            return Json(result);
        }

 

I am struck on how to map this dataset to my spreadsheet in the cshtml using @(Html.Kendo().Spreadsheet()

Can anyone help me in how to bind the dataset to spreadsheet control in razor view?

 

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 25 Oct 2017, 08:17 AM
Hello Karthik,

The required could be achieved by setting the Sheet DataSource with JavaScript instead of configuring it in the Spreadsheet HTML helper. To do that you can handle the first Render event of the widget:
var shouldLoadData = true;
 
function onRender(e) {
    if (!shouldLoadData) {
        return;
    }
 
    shouldLoadData = false;
 
    var spread = e.sender;
    var sheet = spread.activeSheet();
 
    var dataSource = new kendo.data.DataSource({
        transport: {
            read: '@(Url.Action("Products_Load", "Home"))'
        },
        schema: {
            data: "Data",
            total: "Total"
        },
    });
 
    sheet.setDataSource(dataSource);
}

Attached you will find a small sample, implementing the above suggestion.

Regards,
Veselin Tsvetanov
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
Karthik
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or