Git Product home page Git Product logo

ej2-mvc-grid-copypaste's Introduction

Copying and Pasting Excel Sheet Data to EJ2 Grid ASP.NET MVC

This sample explains about how to perform copy and paste actions in ASP.NET MVC DataGrid.

Cross browser way to copy paste Excel sheet data to ASP.NET MVC Grid.

Register paste event for the grid element and handle the process the pasted data.

[Index.cshtml]

document.getElementById('grid').addEventListener(ej.base.Browser.isIE ? 'keydown' : 'paste', function (e) {
        var tsv;
        if (e.ctrlKey && (e.keyCode == 86)) { //Handle copy paste in IE.
            tsv = window.clipboardData.getData('Text');
        } else {
            tsv = e.clipboardData.getData('Text')
        }
        if (tsv) {
            var ajax = new ej.base.Ajax("@Url.Action("OnPaste")");
            ajax.type = "POST";
            ajax.send(JSON.stringify({ pastedData: tsvJSON(tsv) }))
                .then(function (data) {
                    var grid = document.getElementById('grid').ej2_instances[0];
                    grid.dataSource = JSON.parse(data);
                });
        }
    });

Add a controller action to merge pasted data with the actual data and bound the result to the grid.

[HomeController.cs]

[HttpPost]
public ActionResult OnPaste(PostData data, string action)
{
    OrdersList.AddRange(data.pastedData);
    return Json(OrdersList);
}

Prerequisites

  • Visual Studio 2022

How to run the project

  • Checkout this project to a location in your disk.
  • Open the solution file using the Visual Studio 2022.
  • Restore the NuGet packages by rebuilding the solution.
  • Run the project.
  • Placed excel file in project location. Copy the rows and paste it within a Grid.

ej2-mvc-grid-copypaste's People

Contributors

rajendranr-5483 avatar sarubala20 avatar syncfusionbuild avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ganesanvelusamy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.