Implementation Code of jQuery Excel-like table editing

Source: Internet
Author: User

In Excel, you can perform almost all operations on webpages, such as dragging and copying, Ctrl + C, and Ctrl + V.

In addition, it supports the following browsers: IE7 +, FF, Chrome, Safari, and Opera.

How to use:
First, introduce the JS and CSS files related to the jQuery framework and Handsontable plug-ins on the page. The following two files are necessary, and others are optional, if you need a function (see the demo), add it.

Copy codeThe Code is 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 for rendering the Excel editing table

Copy codeThe Code is as follows:
<Div id = "example1"> </div>

Finally, you can initialize it.

Copy codeThe Code is 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 );
CSS ({
Background: 'yellow'
});
};
// Green Rendering Method
Var greenRenderer = function (instance, td, row, col, prop, value, cellProperties ){
Handsontable. TextCell. renderer. apply (this, arguments );
CSS ({
Background: 'green'
});
};
// Initialization
Var $ container = $ ("# example1 ");
$ Container. handsontable ({
Data: data,
StartRows: 5,
ColHeaders: true,
MinSpareRows: 1,
Columns :[
{Data: "id "},
{Data: "name", type: {renderer: yellowRenderer }}, // yellow Rendering
{Data: "isActive", type: Handsontable. CheckboxCell}, // multiple 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 is loaded:

Demo code:

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<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 );
CSS ({
Background: 'yellow'
});
};
// Green Rendering Method
Var greenRenderer = function (instance, td, row, col, prop, value, cellProperties ){
Handsontable. TextCell. renderer. apply (this, arguments );
CSS ({
Background: 'green'
});
};
// Initialization
Var $ container = $ ("# example1 ");
$ Container. handsontable ({
Data: data,
StartRows: 5,
ColHeaders: true,
MinSpareRows: 1,
Columns :[
{Data: "id "},
{Data: "name", type: {renderer: yellowRenderer }}, // yellow Rendering
{Data: "isActive", type: Handsontable. CheckboxCell}, // multiple 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>
</Head>
<Body>
<Div id = "example1"> </div>
</Body>
</Html>

Related Article

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.