question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

merge various Cells in bootstrap Table

See original GitHub issue

I’m new to bootstrap table, I’m using the method MergeCells bootstraptable, I once operated at what I did the following code to unify several rows, I wonder what I’m doing wrong.

$(function () {

            var table = document.getElementById('table');
            var rowLength = table.rows.length - 1;
            var count = 0;
            var row = table.rows[1].cells[0].innerHTML;
            var saveIndex = 0;
            for (var i = 0; i < rowLength; i += 1) {
                if (row === table.rows[i].cells[0].innerHTML) {
                    count++;
                } else {
                    row === table.rows[i].cells[0].innerHTML;
                    mergeRows(saveIndex, count);
                    saveIndex = i;
                    count = 0;
                }
            }
        });

        function mergeRows(index, rowspan) {
            $('#table').bootstrapTable('mergeCells', {
                index: index,
                field: 'ciudad',
                rowspan: rowspan
            });

        }

What I do is call bootstrap function and unify according to the types of records

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dabroscommented, Oct 9, 2015

Solution: http://jsfiddle.net/dabros/sz42rymd/4/

Read the lines i changed carefully, your use of starting ints was wrong (super obvious when debugging) and placing console.log calls in merging function helped fix saveIndex issue.

Seemed to be indexing and a typo on your part (what was the second “===” doing there in an assignment???)

Still, read note in previous comment and refactor that code into a ‘OnPostBody’ or similar callback if still wanting to use it, even if you dont intent to add sorting, filters or any more functionality to the table - its still better form in case you use that code anywhere else or go back to it later to add more.

Its not thoroughly tested either, but should work on any data-set size.

For future referance, always debug first - liberal use of console.log is recommended (see my fiddle). 90% of the time it is always something simple like indexing or variable mismatch, which is why console exists : )

0reactions
Janbsicommented, Oct 9, 2015

thanks @dabros 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating merged table cells using Twitter Bootstrap
Break up your table headers into rows, according to their levels. So the first table row will consist of your "parent" headers, i.e....
Read more >
How to combine or merge cells in an HTML table
Highlight two or more cells in your table. · Right-click the highlighted cells. · Click Modify and then select Merge Cells.
Read more >
FAQ - Bootstrap Table
How to better merge cells? For merged cells, when you do refresh, next page or switch columns to show, the merge cells will...
Read more >
Merge cells vertically from a table - Material Design for Bootstrap
Hi,. may you use our snippets (https://mdbootstrap.com/snippets) to show your example? Thank you. Best,. Piotr.
Read more >
Tables - Bootstrap
Add .table-bordered for borders on all sides of the table and cells. #, First, Last, Handle. 1, Mark, Otto, @mdo. 2, Jacob, Thornton ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found