Constructor Attributes | Constructor Name and Description |
---|---|
REDIPS.table Version 1.2.0
REDIPS.table is a JavaScript library which enables dynamically merging and splitting table cells. |
Field Attributes | Field Name and Description |
---|---|
color.cell defines background color for marked table cell.
|
|
Enable / disable marking not empty table cells.
|
Method Attributes | Method Name and Description |
---|---|
cellIgnore(c)
Method removes attached onMouseDown event listener.
|
|
cellIndex(flag)
Display cellIndex for each cell in tables.
|
|
column(table, mode, index)
Add or delete table column.
|
|
mark(flag, el, row, col)
Method sets or removes mark from table cell.
|
|
merge(mode, clear, table)
Method merges marked table cells horizontally or vertically.
|
|
onMouseDown(el, flag, type)
Method attaches or removes onMouseDown event listener on TD elements depending on second parameter value (default is true).
|
|
row(table, mode, index)
Add or delete table row.
|
|
split(mode, table)
Method splits marked table cell only if cell has colspan/rowspan greater then 1.
|
Field Detail
{Object} color
color.cell defines background color for marked table cell. If not set then background color will not be changed.
// set "#9BB3DA" as color for marked cell REDIPS.table.color.cell = '#9BB3DA';
- Default Value:
- null
{Boolean} markNonEmpty
Enable / disable marking not empty table cells.
// allow marking only empty cells REDIPS.table.markNonEmpty = false;
- Default Value:
- true
Method Detail
cellIgnore(c)
Method removes attached onMouseDown event listener. Sometimes is needed to manually ignore some cells in table after row/column is dynamically added.
- Parameters:
- {HTMLElement|String} c
- Cell id or cell reference of table that should be ignored (onMouseDown event listener will be removed).
cellIndex(flag)
Display cellIndex for each cell in tables. It is useful in debuging process.
- Parameters:
- {Boolean} flag
- If set to true then cell content will be replaced with cell index.
column(table, mode, index)
Add or delete table column. Last column will be assumed if index is omitted.
- Parameters:
- {HTMLElement|String} table
- Table id or table reference.
- {String} mode
- Insert / delete table column
- {Integer} index Optional
- Index where column will be inserted or deleted. Last column will be assumed if index is not defined.
mark(flag, el, row, col)
Method sets or removes mark from table cell. It can be called on several ways: with direct cell address (cell reference or cell id) or with cell coordinates (row and column).
// set mark to the cell with "mycell" reference REDIPS.table.mark(true, mycell); // remove mark from the cell with id "a1" REDIPS.table.mark(false, 'a1'); // set mark to the cell with coordinates (1,2) on table with reference "mytable" REDIPS.table.mark(true, mytable, 1, 2); // remove mark from the cell with coordinates (4,5) on table with id "t3" REDIPS.table.mark(false, 't3', 4, 5);
- Parameters:
- {Boolean} flag
- If set to true then TD will be marked, otherwise table cell will be cleaned.
- {HTMLElement|String} el
- Cell reference or id of table cell. Or it can be table reference or id of the table.
- {Integer} row Optional
- Row of the cell.
- {Integer} col Optional
- Column of the cell.
merge(mode, clear, table)
Method merges marked table cells horizontally or vertically.
- Parameters:
- {String} mode
- Merge type: h – horizontally, v – vertically. Default is “h”.
- {Boolean} clear Optional
- true – cells will be clean (without mark) after merging, false – cells will remain marked after merging. Default is “true”.
- {HTMLElement|String} table Optional
- Table id or table reference.
onMouseDown(el, flag, type)
Method attaches or removes onMouseDown event listener on TD elements depending on second parameter value (default is true). If third parameter is set to “classname” then tables will be selected by class name (named in first parameter). All found tables will be saved in internal array. Sending reference in this case will not be needed when calling merge or split method. Table cells marked with class name “ignore” will not have attached onMouseDown event listener (in short, these table cells will be ignored).
// activate onMouseDown event listener on cells within table with id="mainTable" REDIPS.table.onMouseDown('mainTable', true); // activate onMouseDown event listener on cells for tables with class="blue" REDIPS.table.onMouseDown('blue', true, 'classname');
- Parameters:
- {String|HTMLElement} el
- Container Id. TD elements within container will have added onMouseDown event listener.
- {Boolean} flag Optional
- If set to true then onMouseDown event listener will be attached to every table cell.
- {String} type Optional
- If set to “class name” then all tables with a given class name (first parameter is considered as class name) will be initialized. Default is container/table reference or container/table id.
{HTMLElement} row(table, mode, index)
Add or delete table row. If index is omitted then index of last row will be used.
- Parameters:
- {HTMLElement|String} table
- Table id or table reference.
- {String} mode
- Insert/delete table row
- {Integer} index Optional
- Index where row will be inserted or deleted. Last row will be assumed if index is not defined.
- Returns:
- {HTMLElement} Returns reference of inserted row or NULL (in case of deleting row).
split(mode, table)
Method splits marked table cell only if cell has colspan/rowspan greater then 1.
- Parameters:
- {String} mode
- Split type: h – horizontally, v – vertically. Default is “h”.
- {HTMLElement|String} table Optional
- Table id or table reference.
Thank you for pointing this out -I am very impressed how this is achieved now. It would be great to be able to initiate each tables.I really want to know extending the multi-select capabilities.I must say you done incredibly flexible and very friendly to visual customizations!
Thanks for sharing.
@error 1079 – I’m glad you like my work. REDIPS.table has been created to allow dynamically merge/split table cells and to add/delete table rows and columns. After loading redips-table.js is possible to mark table cells (with a mouse click) and to call REDIPS.table.merge() method. So, multiselect of table cells exists and you can select table cells in several rows or columns and to call merge() method.
@Dbunic: I try to merge vertical cells by changing your example 02. But it isn’t successful. Can you help me?
Thank you.
@Phuong Tran Tuan – Example02 has only 2 rows: row 0 and row 1. Here is how to merge cells in 3rd column:
So, don’t forget that first row and first column starts width index 0. Next, you can comment last line and set mark color to see which cells will be marked (before merging):
How can i call a function when a div is moved and how to get the data for where it is moved to?
@jesper – I suppose that your question is related to REDIPS.drag library (this post is documentation for REDIPS.table). Both libraries can be combined to dynamically merge/split cells and drag DIV elements across tables. Anyway, if some code should be executed after DIV element is moved then define myhandler_moved() event handler and place custom JS code inside (demos in redips2.tar.gz contain a lot of examples how to use event handlers).
And please see documentation for get_position() method how to obtain source and target positions for the dropped DIV element.
Is there a re-load option or load data option for example 24, The data is displayed and I can save, I can’t see a function to reload and continue with the edit?
@Kevin – The easiest way is to generate HTML table with server side script. All client side logic is prepared and you will have to write simple PHP/ASPX/JSP loop to create TR/TD with filled DIV elements. This is the similar to the example03 where you can see how it’s done with PHP. Hope this will not be a problem for you.
Hi,
Your code is very helpful.
I would like to select (mark) two columns, one after another and merge them such that the each row will be individually merged.
Could you please suggest some code?
Thanks,
Daniel
@Dan – Here is source from example02/script.js file (complete redips12.tar.gz package can be download from link below post title).
In this example, cells are marked one by one, but in your case you can create loop that will go through each row and select cells in desired column. After cells are marked, just call merge() method (in “horizontal” mode).
Hello!
Great code! Very useful!
Can u help me with a situation where I need to insert values from a drop down menu and enter it into the selected cells?
Thanks :)
@Newbie – Here is small JS function that will copy dropdown value to the selected table cells. First see needed HTML:
And here is JavaScript function:
Hope this code will be helpful. Cheers!
Thanks heaps! Immensely useful! :)
@Newbie – No problem and I’m glad my reply was helpful for you.
Keep the good job on
@Luca – Right now my free time is a bit limited, but I’ll try to continue working on this site. Thank you!
Great job dbunic ! Thank you.
My problem is when i insert a row below another one by using “x / +” column.
From example 24 (REDIPS_drag), click “+” adds a new row below ; but in my case, i would like to clone the current row, where it can be merged horizontally or vertically… Any idea to do that please ? :)
You already needed to persist table merge in some database?
Hello…
First of all thanks for this great tool!!!
can you help me?
Related to example 24:
After adding a new row, the last column “x / + ” permits the place of the objects while in the first one not.
I understand that the sentence cancels the placement of objects, but this is possible just in the first row. The new ones.
How can I persist this kind of class in the new rows?
This is needed because the column “x/+” should remain empty always.
Thanks for your help!
Adolfo
solved with: lc.className = “redips-mark ignore”;
Thanks!