Code _jquery for adjacent cells of the same text in a merged table based on jquery

Source: Internet
Author: User

One

The data tables that have been generated are roughly as follows:

number
Area Area Product Code Product Name Quantity valid until Distance effect (month) Product BatchSpecifications units Barcode
Guangdong Shenzhen 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil
Guangdong Guangzhou 00027 White Flower Oil
Guangdong Guangzhou 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil
Guangdong Shenzhen 00028 Safflower oil

You need to automatically merge adjacent cells with the same text in the first four columns, and then merge as follows:

number
Area Area Product Code Product Name Quantity valid until Distance effect (month) Product BatchSpecifications units Barcode
Guangdong Shenzhen 00028 Safflower oil
Guangzhou 00027 White Flower Oil
00028 Safflower oil
Shenzhen

1, the introduction of jquery in the head of the HTML

2, add a merged cell function

Copy Code code as follows:

Function Description: Merges the adjacent cells of the same text with the specified table (table ID _w_table_id) that specifies the column (the number of columns is _w_table_colnum)
Parameter description: _W_TABLE_ID is the ID of the table for which you want to merge cells. If you specify a table id= "data" in HTML, this parameter should be #data
Parameter description: _w_table_colnum is the column where you want to merge the cells. As a number, starting from the leftmost first column 1.
function _w_table_rowspan (_w_table_id,_w_table_colnum) {
_W_TABLE_FIRSTTD = "";
_W_TABLE_CURRENTTD = "";
_w_table_spannum = 0;
_w_table_obj = $ (_w_table_id + "tr td:nth-child (" + _w_table_colnum +) ");
_w_table_obj.each (function (i) {
if (i==0) {
_W_TABLE_FIRSTTD = $ (this);
_w_table_spannum = 1;
}else{
_W_TABLE_CURRENTTD = $ (this);
if (_w_table_firsttd.text () ==_w_table_currenttd.text ()) {
_w_table_spannum++;
_w_table_currenttd.hide (); Remove ();
_w_table_firsttd.attr ("RowSpan", _w_table_spannum);
}else{
_W_TABLE_FIRSTTD = $ (this);
_w_table_spannum = 1;
}
}
});
}

Function Description: Merges the adjacent cells of the same text with the specified table (table ID _w_table_id) that specifies the row (the number of rows is _w_table_rownum)
Parameter description: _W_TABLE_ID is the table ID for the merged cells that you want. If you specify a table id= "data" in HTML, this parameter should be #data
Parameter description: _w_table_rownum is the row where you want to merge cells. Refer to the parameters of the Nth-child in jquery for its parameter form.
If it is a number, start with the first Act 1 on the left.
"Even" means even rows
"Odd" means odd rows
The number of rows represented by "3n+1" is 1, 4, 7, 10.
Parameter description: _w_table_maxcolnum The maximum number of columns for the cell in the specified row, and the cells with the number of columns greater than this value will not be merged.
This parameter can be empty, and null to specify that all cells for the specified row are compared to merge.
function _w_table_colspan (_w_table_id,_w_table_rownum,_w_table_maxcolnum) {
if (_w_table_maxcolnum = = void 0) {_w_table_maxcolnum=0}
_W_TABLE_FIRSTTD = "";
_W_TABLE_CURRENTTD = "";
_w_table_spannum = 0;
$ (_w_table_id + "tr:nth-child (" + _w_table_rownum + ")"). each (function (i) {
_w_table_obj = $ (this). Children ();
_w_table_obj.each (function (i) {
if (i==0) {
_W_TABLE_FIRSTTD = $ (this);
_w_table_spannum = 1;
}else if ((_w_table_maxcolnum>0) && (i>_w_table_maxcolnum)) {
Return "";
}else{
_W_TABLE_CURRENTTD = $ (this);
if (_w_table_firsttd.text () ==_w_table_currenttd.text ()) {
_w_table_spannum++;
_w_table_currenttd.hide (); Remove ();
_w_table_firsttd.attr ("ColSpan", _w_table_spannum);
}else{
_W_TABLE_FIRSTTD = $ (this);
_w_table_spannum = 1;
}
}
});
});
}

3, in the head of the HTML call merge functions merged cells
Copy Code code as follows:

<script type= "Text/javascript" ><!--
$ (document). Ready (function () {
_w_table_rowspan ("#spdata", 4);
_w_table_rowspan ("#spdata", 3);
_w_table_rowspan ("#spdata", 2);
_w_table_rowspan ("#spdata", 1);
});
-->
</script>

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.