SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extract Column Informantion

    Hi

    I have a large table with too many columns, I have a column show / hide script. Just to reduce the script size, I want to do some modification.

    On the First ROW of the Table, there are columns heading, and each have an ID. i.e. <image id="col1"...>

    Now, I want to have a function where if I pass the ID, it determine the column index it self, OR if I pass the column Index, it will return the column ID.

    So a simple function that can do either of the two above. Please guide !

    Thanks
    Zeeshan

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't really add any sanity checking.
    Code:
    function getId(columnIndex, tableElement) {
        return tableElement.rows[0].cols[columnIndex].id;
    }
    
    function getColumnIndex(id) {
        var cols = document.getElementById(id).parentNode.rows[0];
        for (var i=0, m=cols.length; i<m; i++) {
            if (cols[i].id === id) {
                return i;
            }
        }
        return false;
    }

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Sir ! You are really a STAR !


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •