Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:42+00:00 2026-05-29T05:34:42+00:00

I want to add colspan or rowspan on a table data The situation is

  • 0

I want to add colspan or rowspan on a table data

The situation is like I have a table of say 5×5, I want to merge columns by selecting say 2 columns by selecting them with mouse and want to merge. This is easy and I’m able to do till this but issue comes when

table with colspan

yellow shows colspan(merged)

and I try to do something like

Red shows what I want to merge

Red shows what I want to merge so the final output should be all six cells merged into 1 and there are many other case of this type which can be seen.
So please guide me the way to proceed for the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:34:42+00:00Added an answer on May 29, 2026 at 5:34 am

    You can do it like this, perhaps not the most elegant but it works, i hope it works for you:

    first prepare the table with attributes.

    function prepare()
        {
            var row = 0;
            $('table tr').each(function ()
            {
                var tr = $(this);
                var curCol = 0;
                var caught = $(this).data('caught');
                $('td', this).each(function (index)
                {
                    while (caught && caught[curCol])
                        curCol++;
    
                    var colspan = $(this).attr('colspan') || 1;
                    var rowspan = $(this).attr('rowspan');
    
                    $(this).attr('start', curCol);
                    $(this).attr('end', curCol + colspan - 1);
                    $(this).attr('startrow', row);
                    $(this).attr('endrow', row + rowspan - 1);
    
    
    
                    var next_tr = tr.next();
                    for (var i = 0; i < rowspan - 1; i++)
                    {
                        var curCaught = next_tr.data('caught') || [];
                        for (var j = curCol; j < curCol + colspan; j++)
                            curCaught[j] = true;
                        next_tr.data('caught', curCaught);
                        next_tr = next_tr.next();
                    }
    
                    curCol += colspan;
                });
                row++;
            })
        }
    

    then you can call this function sending it the selected tdies:

    function getBoundingRectangle(tds)
        {
            var minCol = tds.min(function(){return $(this).attr('start');});
            var maxCol = tds.max(function(){return $(this).attr('end');});
    
            var minrow = tds.min(function(){return $(this).attr('startrow');});
            var maxrow = tds.max(function(){return $(this).attr('endrow');});
    
            var rec = $('td').filter(function()
            {
                var startRow = $(this).attr('startrow');
                var startCol = $(this).attr('start');
    
                var endRow = $(this).attr('endrow');
                var endCol = $(this).attr('end');
    
            return (startRow >= minrow && startRow <= maxrow && startCol >= minCol && startCol <= maxCol) ||
                   (endRow >= minrow && endRow <= maxrow && endCol >= minCol && endCol <= maxCol);
            });
    
            if (rec.length == tds.length)
            {
                debugger;
                var first = rec.filter('[start=' + minCol + '][startrow=' + minrow + ']')
                rec.not(first).remove();
                first.attr('colspan', maxCol - minCol + 1);
                first.attr('rowspan', maxrow - minrow + 1);
    
                return rec;
            }
            else return getBoundingRectangle(rec);
        }
    

    also add the next utility functions:

    $.fn.max = function(func)
        {
            var arr = this.map(func).toArray();
    
            return Math.max.apply( Math, arr );
    
        };
    
        $.fn.min = function(func)
        {
            var arr = this.map(func).toArray();
    
            return Math.min.apply( Math, arr );
    
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dbml with single table users i want add partial class for User
I have a table and I want from user add rows which who want.
I have an HTML table, to which I would like to add or remove
I have a website built with ASP.NET (3.5) and want add some level of
I have a list of string values that I want add to a hashtable
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)
I have a table where the user can add rows to it but each
I have a HTML table which I add items to from javascript on an
Why i have an error in my web.xml when i want add servlet..? <servlet>
I want add two textview with orientation vertical(One below other) in a table row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.