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

  • Home
  • SEARCH
  • 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 332177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:50:35+00:00 2026-05-12T09:50:35+00:00

I have been working on a scheduling website for the past few weeks. I

  • 0

I have been working on a scheduling website for the past few weeks. I am showing the schedules as PHP generated html-tables. I use merged cells for showing events. I have come to a problem when trying to delete events using JS. Since those are merged cells, using rowspan, I have to go through the table and re-adding empty cells whenever there is a need when I delete one. My solution is working fine for when my table contains one merged cell among nothing but empty cells, but with a more complex table, it fails. I can’t really grasp what’s wrong with it, except that it doesn’t correctly find the cellIndex anymore. Does anyone have a clue? Here is what I’m talking about:

http://aturpin.mangerinc.com/table.html

(Click on an event to remove it, or attempt to anyhow)

  • 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-12T09:50:35+00:00Added an answer on May 12, 2026 at 9:50 am

    This sample may help you find your solution. It seems to demonstrate your problem as well as have some sample code to generate a matrix to help you solve it.

    EDIT: I liked the puzzle and decided to play with it for a bit, here is a “functioning” example of implementing that sample (although sometimes the table doesn’t seem to redraw correctly. This should probably help you get further along the way.

    function getTableState(t) {
        var matrix = [];
        var lookup = {};
        var trs = t.getElementsByTagName('TR');
        var c;
        for (var i=0; trs[i]; i++) {
          lookup[i] = [];
            for (var j=0; c = trs[i].cells[j]; j++) {
                var rowIndex = c.parentNode.rowIndex;
                var rowSpan = c.rowSpan || 1;
                var colSpan = c.colSpan || 1;
                var firstAvailCol;
    
                // initalized the matrix in this row if needed.
                if(typeof(matrix[rowIndex])=="undefined") { matrix[rowIndex] = []; }
    
                // Find first available column in the first row
                for (var k=0; k<matrix[rowIndex].length+1; k++) {
                    if (typeof(matrix[rowIndex][k])=="undefined") {
                        firstAvailCol = k;
                        break;
                    }
                }
                lookup[rowIndex][c.cellIndex] = firstAvailCol;
                for (var k=rowIndex; k<rowIndex+rowSpan; k++) {
                    if(typeof(matrix[k])=="undefined") { matrix[k] = []; }
                    var matrixrow = matrix[k];
                    for (var l=firstAvailCol; l<firstAvailCol+colSpan; l++) {
                        matrixrow[l] = {cell: c, rowIndex: rowIndex};
                    }
                }
            }
        }
    
        // lets build a little object that has some useful funcitons for this table state.
        return {
          cellMatrix: matrix,
          lookupTable: lookup,
    
          // returns the "Real" column number from a passed in cell
          getRealColFromElement: function (cell)
          {
            var row = cell.parentNode.rowIndex;
            var col = cell.cellIndex;
            return this.lookupTable[row][col];          
          },
          // returns the "point" to insert at for a square in the perceived row/column
          getPointForRowAndColumn: function (row,col)
          {
            var matrixRow = this.cellMatrix[row];
            var ret = 0;
            // lets look at the matrix again - this time any row that shouldn't be in this row doesn't count.
            for (var i=0; i<col; i++)
            {
              if (matrixRow[i].rowIndex == row) ret++;
            }
            return ret;
          }
        };
    }
    
    function scheduleClick(e)
    {
        if (e.target.className != 'event')
            return;
    
        //Get useful info before deletion
        var numRows = e.target.rowSpan;
        var cellIndex = e.target.cellIndex;
        var rowIndex = e.target.parentNode.rowIndex;
        var table = e.target.parentNode.parentNode;
    
        var tableState = getTableState(table);
    
        var colIndex = tableState.getRealColFromElement(e.target);
    
        //Deletion
        e.target.parentNode.deleteCell(cellIndex);
    
        //Insert empty cells in each row
        for(var i = 0; i < numRows; i++)
        {
            var row = table.rows[rowIndex + i];
            row.insertCell(tableState.getPointForRowAndColumn(rowIndex+i, colIndex));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working as a native C++ programmer for last few years. Now
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with a string[] array in C# that gets returned from
We have been working with CVS for years, and frequently find it useful to
I have been working on some legacy C++ code that uses variable length structures
I have been working with relational databases for sometime, but it only recently occurred
I have been working with Struts for some time, but for a project I
I have been working on a childish little program: there are a bunch of
I have been working on a wrapper for a COM object that can only

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.