The implementation code of jquery copy Excel table editing function _jquery

Source: Internet
Author: User

The things you can do in Excel, you can almost do it in a Web page, such as drag copying, CTRL + C, CTRL + V, and so on.

In addition to browser support, it supports the following browsers ie7+, FF, Chrome, Safari, Opera.

How to use:
First of all, introduce the JQuery framework and the related JS and CSS files of the handsontable plug-ins in the page, and the following two are necessary, and others are optional, if a feature is needed (see demo).

Copy Code code as follows:

<script src= "Jquery.min.js" ></script>
<script src= "Jquery.handsontable.full.js" ></script>
<link rel= "stylesheet" href= "Jquery.handsontable.full.css" >

Then add a DIV layer to render the Excel editing table

Copy Code code as follows:

<div id= "example1" ></div>

You can finally initialize it.

Copy Code code as follows:

Data
var data = [
{id:1, Name: "Ted", Isactive:true, Color: "Orange"},
{id:2, Name: "John", Isactive:false, Color: "Black"},
{id:3, Name: "Al", Isactive:true, Color: "Red"},
{id:4, Name: "Ben", Isactive:false, Color: "Blue"}
];
Yellow Rendering method
var yellowrenderer = function (instance, TD, Row, COL, prop, value, cellproperties) {
Handsontable.TextCell.renderer.apply (this, arguments);
$ (TD). CSS ({
Background: ' Yellow '
});
};
Green Rendering method
var greenrenderer = function (instance, TD, Row, COL, prop, value, cellproperties) {
Handsontable.TextCell.renderer.apply (this, arguments);
$ (TD). CSS ({
Background: ' Green '
});
};
Class
var $container = $ ("#example1");
$container. handsontable ({
Data:data,
Startrows:5,
Colheaders:true,
Minsparerows:1,
Columns: [
{data: "id"},
{data: ' name ', type: {renderer:yellowrenderer}},//Yellow render
{data: ' IsActive ', Type:Handsontable.CheckboxCell},//Multi-selection box
{data: "Color",
Type:Handsontable.AutocompleteCell,//automatic completion
Source: ["Yellow", "red", "orange", "green", "blue", "gray", "Black", "white"]//Data source
}
],
Cells:function (Row, col, prop) {
if (row = = 0 && col = 0) {
return {type: {renderer:greenrenderer}};
}
}
});

Note that the DIV container is initialized after it has finished loading:

Demo Code:

Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>basic demo</title>
<script src= "Jquery.min.js" ></script>
<script src= "Jquery.handsontable.full.js" ></script>
<link rel= "stylesheet" href= "Jquery.handsontable.full.css" >
<script>
$ (function () {
Data
var data = [
{id:1, Name: "Ted", Isactive:true, Color: "Orange"},
{id:2, Name: "John", Isactive:false, Color: "Black"},
{id:3, Name: "Al", Isactive:true, Color: "Red"},
{id:4, Name: "Ben", Isactive:false, Color: "Blue"}
];
Yellow Rendering method
var yellowrenderer = function (instance, TD, Row, COL, prop, value, cellproperties) {
Handsontable.TextCell.renderer.apply (this, arguments);
$ (TD). CSS ({
Background: ' Yellow '
});
};
Green Rendering method
var greenrenderer = function (instance, TD, Row, COL, prop, value, cellproperties) {
Handsontable.TextCell.renderer.apply (this, arguments);
$ (TD). CSS ({
Background: ' Green '
});
};
Class
var $container = $ ("#example1");
$container. handsontable ({
Data:data,
Startrows:5,
Colheaders:true,
Minsparerows:1,
Columns: [
{data: "id"},
{data: ' name ', type: {renderer:yellowrenderer}},//Yellow render
{data: ' IsActive ', Type:Handsontable.CheckboxCell},//Multi-selection box
{data: "Color",
Type:Handsontable.AutocompleteCell,//automatic completion
Source: ["Yellow", "red", "orange", "green", "blue", "gray", "Black", "white"]//Data source
}
],
Cells:function (Row, col, prop) {
if (row = = 0 && col = 0) {
return {type: {renderer:greenrenderer}};
}
}
});
});
</script>
<body>
<div id= "example1" ></div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.