This is a migrated thread and some comments may be shown as answers.
MVC rid - Paste data from excel
1 Answer 27 Views
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 24 Jul 2017, 07:57 AM

Is it possible to paste data from Excel and have the create method fire to append each inserted row?

The example from the documentation (http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/excel/copy-from-excel-to-grid) simply replaces the existing grid's datasource whereas I would like to append each row that is pasted in so that it maintains the existing data and adds the newly pasted data.

My example Grid currently looks like:

@(Html.Kendo().Grid<InvoiceDetailVM>()
.Name("MyGrid")
.Columns(columns =>
{
columns.Bound(p => p.ID).Hidden();
columns.Bound(p => p.Description);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
})

.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()

.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax()                                                    
.PageSize(25)
.Events(events => events.Error("window.KendoGrid_Error"))
.Model(model =>
{
model.Id(i => i.ID); // Specify the property which is the unique identifier of the model.
model.Field(i => i.ID).Editable(false);
})
.Create(update => update.Action("Create", "Test"))
.Read(read => read.Action("Read", "Test"))
.Update(update => update.Action("Edit"))
.Destroy(update => update.Action("Delete", "Test"))
)                                
)

Any help would be appreciated.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 26 Jul 2017, 05:58 AM
Hello Mark,

The desired result can be achieved by retrieving the current data before adding the new one. The data can be retrieved using the data method of the dataSource:

https://admin.telerik.com/docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-data

// This is the changed line
var
data = grid.dataSource.data();
 
           for (var i = 0; i < rows.length; i++) {
             var cells = rows[i].split('\t');
             data.push({
               Name: cells[0],
               Age: cells[1]
             });
           };
           grid.dataSource.data(data);

http://dojo.telerik.com/utENI

I hope this is helpful.

Regards,
Stefan
Progress Telerik
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 (charts) and form elements.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or