SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Collapsing Rows

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Collapsing Rows

    All,

    I've been working on some PHP code and need to collapse the data rows. I found several examples of AJAX scripts and put them into a test file. They all work if they are only in the HTML with AJAX, but when I use PHP, assigning the Header or Category Row as the trip or clickable row to a PHP var, with the resulting datarows, I can not get the code to work.

    I'm assuming it is because after the item properties are set by AJAX the PHP would then have to run a refresh sequence to update the var/property setting for the elements in the table.

    I'm doing this on an order site, but also captured my work in sample file for testing. I've uploaded the file in my response to thread:

    http://www.sitepoint.com/forums/showthread.php?t=184350

    Download and rename ext to .php and run it as a test. You will see the first table, which is rendered in PHP will not collapse, all others will.

    I need to determine what else is needed in my code. I'm wondering if I need a hidden field to pass parms to my scripts. I looked all over the internet and found either just the straight examples of HTML/AJAX or code I did not understand, nor did it seem revelant.

    I did find one link talking about a PHP script needed to pass parms to the AJAX, but when I copied their code, quickly found it was not PHP at all, but just another AJAX snippet. Somehow all the AJAX scripts I find do not account for this problem, so I'm left hopelss at this point.

    All help greatly appreciated!

    Thanks!

    OMR

  2. #2
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what does this have to do with php?

    you can collapse rows clientside with libraries like jquery without php being involved at all

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ionix5891 View Post
    you can collapse rows clientside with libraries like jquery without php being involved at all
    Well all rows in my production script are built from data in MySQL and site is all PHP site, so need this to work in existing code.

    OMR

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All,

    Thanks much for the pointers. Got some basic feedback from users at:

    CodeWalkers
    http://forums.devshed.com/php-develo...ml#post2156989

    I knew I was close, mainly just syntax keeping me out. Have made the changes to my sample file and my production file and they work fine. I also moved all three of the tables in the first group into php.

    Now I want these table rows to init in the collapsed state, just like the columns in the second table group. I'm sure the function they used:
    function setupTables() {
    var tables = document.getElementsByTagName('table');
    for (var tableLoop=0; tableLoop<tables.length; tableLoop++) {
    if (tables[tableLoop].className == 'collapseColumns') {
    var headerRow = tables[tableLoop].tHead.rows[0].cells;
    for (var cellLoop=0; cellLoop<headerRow.length; cellLoop++) {
    headerRow[cellLoop].onclick = toggleColumn;
    headerRow[cellLoop].style.cursor = 'pointer';
    }
    }
    }
    }
    is what I need to invoke, but not sure what parms are needed.

    If you know please chime in.

    Thanks a lot again!

    OMR
    Attached Files Attached Files

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All,

    I got this fixed. Found that syntax in my code was major problem. Code is (javascript):
    Code:
        <script language="javascript">
        function getItem(id) {
            var itm = false;
            if(document.getElementById)
                itm = document.getElementById(id);
            else if(document.all)
                itm = document.all[id];
            else if(document.layers)
                itm = document.layers[id];
            return itm;
        }
    
        function toggleItem(id) {
            itm = getItem(id);
            if(!itm)
                return false;
            if(itm.style.display == 'none')
                itm.style.display = '';
            else
                itm.style.display = 'none';
            return false;
        }
        </script>
    (PHP)
    Code:
    <a href='#' onclick=\"toggleItem('myTbody[$i]')\">
    Notice the placement of the single and double quotes and the "\" escape character needed for correct processing.

    Thanks All!

    OMR

  6. #6
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It could be done in 1 line of jQuery...

    $("tr a.toggle").click(function(){$(this).hide()}, function(){$(this).show()}));
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  7. #7
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how exactly is this PHP? ...
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  8. #8
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    how exactly is this PHP? ...
    It's not. Like ionix5891 said.
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  9. #9
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then why is it in a PHP forum? >.>
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  10. #10
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    Then why is it in a PHP forum? >.>
    Because the OP didnt know any better, any because you are keeping the discussion going.
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed


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
  •