Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <table border="1" class="tt">
- <tr>
- <td>TEST</td>
- <td>TEST</td>
- <td colspan="2" rowspan="2">TEST</td>
- </tr>
- <tr>
- <td>TEST</td>
- <td>TEST</td>
- </tr>
- <tr>
- <td>TEST</td>
- <td>TEST</td>
- <td>TEST</td>
- <td>TEST</td>
- </tr>
- </table>
- <div id="rt" class="render_table"></div>
- <div id="rt2" class="render_table"></div>
- <div id="rt3" class="render_table"></div>
- <div id="rt4" class="render_table"></div>
- <style>
- table {
- max-width: 300px;
- border-collapse: collapse;
- }
- .render_table {
- margin-top: 20px;
- }
- .render_table table {
- max-width: 1000px;
- }
- .render_table td div {
- border: none;
- padding: 0;
- width: 100%;
- margin: 0;
- min-height: 100%;
- outline: none;
- text-align: center;
- }
- .render_table td {
- padding: 5px;
- }
- td>div {
- width: 100%;
- height: 100%;
- }
- </style>
- </body>
- </html>
- <script>
- const b = [[{ "colspan": false, "rowspan": false, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 2", "id": "eacfed34-8516-415c-98cb-cb8a44ee2c12", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 3", "id": "9dd8d22a-c56d-4924-8791-f5e472d0be01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 4", "id": "99748fb6-0733-4c5d-9cf6-3d7a007fe463", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 5", "id": "fd0f6c4c-0c32-438f-bbde-36132999ed01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 6", "id": "41f4954d-b9cd-43cc-9956-110a1870e4d8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 7", "id": "d46c0980-7e1b-4088-bf1c-01c70b4192ca", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 8", "id": "e655579d-0db5-4394-8692-5d7811bb22e8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 9", "id": "0111e7c7-6fea-4b47-8a2f-56b0cdc7dcbd", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 1", "id": "cc2cde27-5278-43c7-a009-a67c858e4a33", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 2", "id": "4e088a94-9a20-4c62-b01c-a994dcb90094", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 3", "id": "244dcfa3-8ab4-4b1d-88f1-9fce8fd7d2ec", "styles": {}, "attributes": {} }, { "colspan": 4, "rowspan": false, "value": "Row 2 4", "id": "01476269-a06f-4bc8-8971-1c5bdd071813", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 8", "id": "516cb5dd-1c2e-402a-8ade-44a2bf367d38", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 9", "id": "d1f77561-ea1f-4a90-abf7-f6d960623b2f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 4", "id": "d366a9ee-4458-4ba4-bc5b-a0aca3b58958", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 8", "id": "1112534f-d7f1-420e-9c27-0911dc9fd918", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 6", "id": "91c63856-0a06-49ef-a045-b7f452633e22", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 7", "id": "c1ca0b12-f221-41e0-b1cf-8f4c9b957dc9", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 8", "id": "057f7962-69ad-4f61-9b57-faf063069c87", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const c = [[{ "colspan": false, "rowspan": false, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 2", "id": "eacfed34-8516-415c-98cb-cb8a44ee2c12", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 3", "id": "9dd8d22a-c56d-4924-8791-f5e472d0be01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 4", "id": "99748fb6-0733-4c5d-9cf6-3d7a007fe463", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 5", "id": "fd0f6c4c-0c32-438f-bbde-36132999ed01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 6", "id": "41f4954d-b9cd-43cc-9956-110a1870e4d8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 7", "id": "d46c0980-7e1b-4088-bf1c-01c70b4192ca", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 8", "id": "e655579d-0db5-4394-8692-5d7811bb22e8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 9", "id": "0111e7c7-6fea-4b47-8a2f-56b0cdc7dcbd", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 1", "id": "cc2cde27-5278-43c7-a009-a67c858e4a33", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 2", "id": "4e088a94-9a20-4c62-b01c-a994dcb90094", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 3", "id": "244dcfa3-8ab4-4b1d-88f1-9fce8fd7d2ec", "styles": {}, "attributes": {} }, { "colspan": 5, "rowspan": false, "value": "Row 2 4", "id": "01476269-a06f-4bc8-8971-1c5bdd071813", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 9", "id": "d1f77561-ea1f-4a90-abf7-f6d960623b2f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": 3, "rowspan": false, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 6", "id": "91c63856-0a06-49ef-a045-b7f452633e22", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 7", "id": "c1ca0b12-f221-41e0-b1cf-8f4c9b957dc9", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 8", "id": "057f7962-69ad-4f61-9b57-faf063069c87", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const d = [[{ "colspan": false, "rowspan": false, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 2", "id": "eacfed34-8516-415c-98cb-cb8a44ee2c12", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 3", "id": "9dd8d22a-c56d-4924-8791-f5e472d0be01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 4", "id": "99748fb6-0733-4c5d-9cf6-3d7a007fe463", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 5", "id": "fd0f6c4c-0c32-438f-bbde-36132999ed01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 6", "id": "41f4954d-b9cd-43cc-9956-110a1870e4d8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 7", "id": "d46c0980-7e1b-4088-bf1c-01c70b4192ca", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 8", "id": "e655579d-0db5-4394-8692-5d7811bb22e8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 9", "id": "0111e7c7-6fea-4b47-8a2f-56b0cdc7dcbd", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 1", "id": "cc2cde27-5278-43c7-a009-a67c858e4a33", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 2 2", "id": "4e088a94-9a20-4c62-b01c-a994dcb90094", "styles": {}, "attributes": {} }/* , { "colspan": false, "rowspan": false, "value": "Row 2 3", "id": "244dcfa3-8ab4-4b1d-88f1-9fce8fd7d2ec", "styles": {}, "attributes": {} } */, { "colspan": 5, "rowspan": false, "value": "Row 2 4", "id": "01476269-a06f-4bc8-8971-1c5bdd071813", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 9", "id": "d1f77561-ea1f-4a90-abf7-f6d960623b2f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": 3, "rowspan": 2, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const d1 = [[{ "colspan": false, "rowspan": false, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": 2, "value": "Row 1 2", "id": "eacfed34-8516-415c-98cb-cb8a44ee2c12", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 4", "id": "99748fb6-0733-4c5d-9cf6-3d7a007fe463", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 5", "id": "fd0f6c4c-0c32-438f-bbde-36132999ed01", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 6", "id": "41f4954d-b9cd-43cc-9956-110a1870e4d8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 7", "id": "d46c0980-7e1b-4088-bf1c-01c70b4192ca", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 1 8", "id": "e655579d-0db5-4394-8692-5d7811bb22e8", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 1", "id": "cc2cde27-5278-43c7-a009-a67c858e4a33", "styles": {}, "attributes": {} }, { "colspan": 5, "rowspan": false, "value": "Row 2 4", "id": "01476269-a06f-4bc8-8971-1c5bdd071813", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 9", "id": "d1f77561-ea1f-4a90-abf7-f6d960623b2f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": 3, "rowspan": 2, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const d2 = [[{ "colspan": false, "rowspan": false, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": 8, "rowspan": 2, "value": "Row 1 2", "id": "eacfed34-8516-415c-98cb-cb8a44ee2c12", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 1", "id": "cc2cde27-5278-43c7-a009-a67c858e4a33", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": 3, "rowspan": 2, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const d3 = [[{ "colspan": 9, "rowspan": 2, "value": "Row 1 1", "id": "564c89ee-c3ee-473b-bfd2-f6857a4448e4", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 1 10", "id": "12fb50cc-98e9-4103-9513-e73af49923d7", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 2 10", "id": "e1ea51ca-2c4b-48aa-90b6-6eac6da3a470", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 3 1", "id": "d68da4c3-67aa-4ac3-aacd-7fef9dd018ea", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 2", "id": "45b7e755-f43b-4ac4-a8ff-3a2a08a9c7d4", "styles": {}, "attributes": {} }, { "colspan": 2, "rowspan": false, "value": "Row 3 3", "id": "c156a96f-e640-4abe-b436-62ab9d6c0a3f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 5", "id": "e291f908-36fb-4f2d-8369-073f656fd554", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 6", "id": "747a6791-d583-4df7-8b87-71fb5ff1ab40", "styles": {}, "attributes": {} }, { "colspan": 3, "rowspan": 2, "value": "Row 3 7", "id": "87751af3-77fb-4889-ae34-b8939b07c1e3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 3 10", "id": "67c0e9aa-7453-4732-a6eb-22e2408d0830", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 4 1", "id": "98a71ce5-c0cc-4538-8d33-1b4e52d76fff", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 2", "id": "a71a17b3-08b6-450b-871a-b43d8732b5bf", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 3", "id": "f32f7cd7-3e64-4b22-9693-dab09e59e62e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 4", "id": "5d874eff-1197-4c77-8d9b-10e0ac7bd0d3", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 5", "id": "0ec4df8e-36d1-4efc-a1dd-1c5bb6034cba", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 9", "id": "e25c0d37-5590-4c87-b2b7-1672430d14d2", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 4 10", "id": "fabde90e-2a08-42cf-bc9f-86de050a35ad", "styles": {}, "attributes": {} }], [{ "colspan": false, "rowspan": false, "value": "Row 5 1", "id": "c0e05571-d667-464c-9cec-0dd1a7749e7f", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 2", "id": "97ebf5c4-8a3a-41ca-8044-4c4d80ef7eeb", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 3", "id": "c43f2861-83c3-4079-9005-8cb40fc024f5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 4", "id": "3d81498a-e10f-441b-b3ca-d6faf3caff92", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 5", "id": "1bbbef7c-4235-4878-ae16-c0f2d6b5d1a5", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 6", "id": "f3095ad0-d272-4cce-834a-247de92c1c95", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 7", "id": "dce2ee88-3bcf-4f72-b251-e323a6bd8736", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 8", "id": "7794d5fb-c2dc-4681-8f0f-2c222c6f8d8e", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 9", "id": "a4eec9be-1231-4c48-9195-1e872d978184", "styles": {}, "attributes": {} }, { "colspan": false, "rowspan": false, "value": "Row 5 10", "id": "4b0cf671-411a-47dc-931c-66b4e228dc13", "styles": {}, "attributes": {} }]];
- const tb = new class {
- constructor() {
- this.config = { cols: 10, rows: 5 };
- this.table = new Array(this.config.rows).fill(false).map((t, i) => new Array(this.config.cols)
- .fill(false).map((r, j) => this.createEmpty({ value: `Row ${i + 1} ${j + 1}` })));
- this.table = b;
- this.table = c;
- this.table = d;
- this.table = d1;
- this.table = d2;
- this.table = d3;
- }
- uuidv4() {
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
- (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
- );
- }
- findCeilCoordsById(data = [], ceilId = false) {
- return data.reduce((result, items, i) => {
- items.forEach((item, j) => {
- if (item.id == ceilId) result.push({ i, j });
- });
- return result;
- }, []);
- }
- getCeilById(ceildId) {
- return this.table.reduce((result, items) => {
- const item = items.find(it => it.id == ceildId);
- if (item) return item;
- return result;
- }, false);
- }
- addRow(cellId = 'e291f908-36fb-4f2d-8369-073f656fd554', to = 'after') { // row 3 5
- let data = this.reparse();
- let rowIndex = data.findIndex(items => items.find(q => q.id == cellId));
- let append = false;
- if (rowIndex == -1) {
- rowIndex = to == 'after' ? data.length - 1 : 0;
- append = true;
- }
- const maxCols = Math.max(...data.map(items => items.reduce((r, item) => r + (item.colspan || 1), 0)));
- const indexRows = to == 'after' ? rowIndex : rowIndex - 1;
- const arr = new Array(maxCols).fill(false)
- .map(q => tb.createEmpty())
- .map((item, index) => {
- if (data[indexRows] && !append) {
- const item = data[indexRows][index];
- const { positions } = this.calculatePositions(item.id, data);
- const firstItem = data[positions.y][positions.x];
- console.log('positions', positions);
- if (positions.x == index) {
- if (firstItem && firstItem.cache && firstItem.cache.rowspan > 1) {
- data[positions.y][positions.x].cache.rowspan += 1;
- }
- } else {
- if (firstItem && firstItem.cache && firstItem.cache.rowspan > 1) return false;
- }
- }
- }).filter(q => q);
- data.splice(rowIndex + 1, 0, arr);
- data = data.reduce((result, items) => {
- result.push(items.reduce((r2, item) => {
- if(!result.find(r => r.find(q => q.id == item.id))) {
- console.log('WTF: ', item.value);
- item.rowspan = item.cache ? item.cache.rowspan : 1;
- item.colspan = item.cache ? item.cache.colspan : 1;
- delete item.cache;
- r2.push(item);
- }
- return r2;
- }, []));
- return result;
- }, []);
- tb.insertTable(document.getElementById('rt3'), data);
- }
- addCol(ceilId, to = 'after') {
- const { positions: coords } = this.calculatePositions(ceilId, this.table, false, []);
- const ceil = this.getCeilById(ceilId);
- // this.table.forEach((items, i) => {
- // this.table[]
- // });
- }
- clone(data = {}) {
- return JSON.parse(JSON.stringify(data));
- }
- calculateShiftBlock(data = [], ceilId = false, direction = 'left') {
- const haveInArray = data.find(items => items.find(item => item.id == ceilId));
- if (!haveInArray) return false;
- const { positions } = this.calculatePositions(ceilId, data);
- let result = false;
- if (['bottom', 'top'].includes(direction)) {
- const line = direction == 'bottom' ? positions.bottom : positions.y;
- const incr = direction == 'bottom' ? 1 : -1;
- if (data[line + incr]) {
- const ceils = data[line + incr].filter((ceil, i) => i >= positions.x && i <= positions.right);
- result = ceils.reduce((result, ceil) => {
- return this.calculatePositions(ceil.id, data, result.positions, result.skip);
- }, { skip: [ceilId], positions });
- }
- } else if (['left', 'right'].includes(direction)) {
- const line = direction == 'right' ? positions.right : positions.x;
- const incr = direction == 'right' ? 1 : -1;
- if (data[positions.y] && data[positions.y][line + incr]) {
- const ceils = new Array((positions.bottom - positions.y) + 1).fill(false).map((q, i) => {
- return data[positions.y + i][line + incr];
- });
- result = ceils.reduce((result, ceil) => {
- return this.calculatePositions(ceil.id, data, result.positions, result.skip);
- }, { skip: [ceilId], positions });
- }
- }
- if (!result) return false;
- const itemUpdate = data[result.positions.y][result.positions.x];
- const toRemoveItems = data.reduce((r, items) => {
- items.forEach(item => {
- if (result.skip.find(s => s == item.id) && itemUpdate.id !== item.id && !r.find(q => q == item.id))
- r.push(item.id);
- });
- return r;
- }, []);
- let colspan = (result.positions.right - result.positions.x) + 1;
- let rowspan = (result.positions.bottom - result.positions.y) + 1;
- const maxCols = Math.max(...data.map(items => items.reduce((result, item) => result + (item.colspan || 1), 0)));
- if (maxCols >= colspan && rowspan > 1) rowspan = 1;
- return { itemUpdate: { ...itemUpdate, colspan, rowspan }, toRemoveItems };
- }
- findCeilsByPositions(data, positions = {}, skip = []) {
- return data.reduce((result, items, y) => {
- items.forEach((item, x) => {
- if (x >= positions.x && y >= positions.y && positions.bottom >= y && positions.right >= x) {
- if (!skip.find(s => s == item.id)) result.push(item.id);
- }
- });
- return result;
- }, []);
- }
- calculatePositions(ceilId, data, lastPositions = false, skip = []) {
- const positions = this.findCeilCoordsById(data, ceilId);
- let x = Math.min(...positions.map(q => q.j));
- let y = Math.min(...positions.map(q => q.i));
- let bottom = Math.max(...positions.map(q => q.i));
- let right = Math.max(...positions.map(q => q.j));
- if (!lastPositions) return { positions: { x, y, bottom, right }, skip };
- if (x < lastPositions.x) lastPositions.x = x;
- if (y < lastPositions.y) lastPositions.y = y;
- if (right > lastPositions.right) lastPositions.right = right;
- if (bottom > lastPositions.bottom) lastPositions.bottom = bottom;
- skip.push(ceilId);
- const ceils = this.findCeilsByPositions(data, lastPositions, skip);
- for (const c of ceils) {
- const res = this.calculatePositions(c, data, lastPositions, skip);
- skip = res.skip;
- lastPositions = res.positions;
- }
- return { skip, positions: lastPositions };
- }
- reparse(dataTable = false) {
- const data = this.clone(dataTable || this.table);
- const styles = { background: '#00968855', color: '#000000' };
- const parseItem = (item, styles = {}) => {
- return this.clone({ ...item, cache: { rowspan: item.rowspan, colspan: item.colspan }, rowspan: 1, colspan: 1, styles });
- };
- const modify = [];
- this.clone(data).reduce((r, items, i) => {
- items.reduce((r2, item, j) => {
- const rows = item ? (item.rowspan || 1) : 1;
- const cols = item ? (item.colspan || 1) : 1;
- if (item) {
- if (rows > 1) {
- new Array(rows).fill(false).forEach((q, io) => {
- if (io > 0 && data[r + io]) {
- const arr = new Array(cols).fill(false).map(q => parseItem({
- ...item, value: 'update row', isClone: true
- }, styles));
- data[r + io].splice(r2, 0, ...arr);
- modify.push(item.id);
- }
- });
- }
- if (cols > 1) {
- if (data[r + 1]) {
- const arr = new Array(cols - 1).fill(false)
- .map(q => parseItem({ ...item, value: 'update col', isClone: true }, styles));
- data[r].splice(r2 + 1, 0, ...arr);
- modify.push(item.id);
- }
- }
- }
- return r2 + cols;
- }, 0);
- const minRow = Math.min(...[...items.map(q => (q.rowspan || 1)), 1]);
- return r + minRow;
- }, 0);
- return data.reduce((result, items) => {
- result.push(items.reduce((r, item) => {
- r.push(parseItem(item, modify.find(m => m == item.id) ? styles : {}));
- return r;
- }, []));
- return result;
- }, []);
- }
- createEmpty(options = {}) {
- return {
- colspan: false, rowspan: false, value: ``, id: this.uuidv4(),
- styles: {}, attributes: {}, ...options
- }
- }
- renderTable(data = false) {
- let html = '<table border="1">';
- for (const col of data || this.table) {
- let tr = '<tr>';
- for (const row of col) {
- const stylesString = Object.entries((row.styles || {}))
- .reduce((res, [key, val]) => res += `${key}:${val};`, '');
- const colspan = row.colspan ? ` colspan="${row.colspan}"` : '';
- const rowspan = row.rowspan ? ` rowspan="${row.rowspan}"` : '';
- let q = '';
- if (row.isClone) { q = 'background: #96300055;'; }
- tr += `<td${colspan}${rowspan} data-id="${row.id}" style="${stylesString}${q}">
- <div contentEditable>${row.value}</div>
- </td>`;
- }
- html += `${tr}</tr>`;
- }
- return `${html}</table>`;
- }
- findPositionsCeilById(id) {
- return this.table.reduce((result, data, i) => {
- data.reduce((r, item, j) => {
- if (item.id == id) result = { i, j: r };
- }, 0);
- return result;
- }, { i: 0, j: 0 });
- }
- margeCells(cellId, to = 'left') {
- const result = this.calculateShiftBlock(this.reparse(this.table), cellId, to);
- if (!result) return false;
- this.table = this.table.reduce((r, items) => {
- items = items.map(item => {
- if (item.id == result.itemUpdate.id) return {
- ...item, rowspan: result.itemUpdate.rowspan,
- colspan: result.itemUpdate.colspan,
- };
- if (result.toRemoveItems.find(rd => rd == item.id)) return false;
- return item;
- }).filter(q => q);
- if (items.length) r.push(items);
- return r;
- }, []);
- this.insertTable();
- }
- updateTableByRules(rules = []) {
- this.table = this.table.reduce((result, data) => {
- const updatedRules = data.reduce((r, item) => {
- const rulesFilter = rules.filter(r => r.id == item.id);
- if (rulesFilter && rulesFilter.length) {
- for (let i = 0; i < rulesFilter.length; i++) {
- const rule = rulesFilter[i];
- if (rule) {
- if (rule.type == 'append') {
- r.push(item, this.createEmpty(rule.opts));
- } else {
- item = { ...item, ...rule.opts };
- if (r.find(d => d.id == item.id)) {
- r = r.map(a => a.id == item.id ? ({ ...a, ...item }) : a)
- } else {
- r.push(item);
- }
- }
- } else if (i == 0) { r.push(item); }
- }
- } else {
- r.push(item);
- }
- return r;
- }, []);
- result.push(updatedRules);
- return result;
- }, []);
- }
- insertTable(element = document.getElementById('rt'), data = false) {
- element.innerHTML = this.renderTable(data);
- }
- }
- tb.insertTable();
- tb.insertTable(document.getElementById('rt2'), tb.reparse());
- Array.from(document.querySelector('.tt').querySelectorAll('td')).forEach(td => td.innerHTML = 'Lorem ipsum dolor sit amet consectetur');
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement