Wrap report tables in hidable divs?

(7 posts) (2 voices)

Tags:

No tags yet.

  1. adamhaeder, Member

    I would like to but divs around some of the tables in my reports to made them 'hidable'. I've done this in the past in web pages with some custom javascript. However, I can't seem to figure out how to get my custom javascript to work in my current report. Here is what I'm trying to do:

    select 'dbr.javascript', 'function toggle() { var ele = document.getElementById("toggleText"); var text = document.getElementById("displayText"); if(ele.style.display == "block") {ele.style.display = "none";text.innerHTML = "show";}else {ele.style.display = "block";text.innerHTML = "hide";}}', 'onload';

    select 'dbr.purehtml', 'show<div id="toggleText" class="left" style="display: none">'; SELECT * FROM datawarehouse.companies LIMIT 10; select 'dbr.purehtml', '</div>';

    When I run the report and click on 'show', I get the javascript error: Uncaught ReferenceError: toggle is not defined

    Is there a better way to do this?

  2. myDBR Team, Key Master

    Easiest way is to use jQuery which is used by myDBR.

    If you only have one result table to hide, you can directly hide the table by assigning a class to the result and attach the jQuery toggle()-call to the class:

    select 'dbr.purehtml', '<button onclick="$(\'.hide_me\').toggle();">Hide/show</button>';
    select 'dbr.resultclass', 'hide_me'; SELECT * FROM datawarehouse.companies LIMIT 10;

    If you have multiple results or want to use slide effects, wrap the result table to a span/div and attach the jQuery slideToggle()-call to the class.

    select 'dbr.purehtml', '<button onclick="$(\'.hide_me\').slideToggle();">Hide/show</button><div class="hide_me">';
    
    SELECT * FROM datawarehouse.companies LIMIT 10;
    
    select 'dbr.purehtml','</div>';

    --
    myDBR Team

  3. adamhaeder, Member

    Well that's about 100% better than what I was trying to do. Works great. Thanks so much.

  4. adamhaeder, Member

    I added a little javascript to this to make the button be "-" to hide and then change to "+" to show again.

    select 'dbr.title', ''; select 'dbr.purehtml', '<table><tr><td valign="top"><button id=show1 onclick="$(\'.hide_me\').slideToggle(); text=document.getElementById(\'show1\');if (text.innerHTML == \'+\') { text.innerHTML = \'-\'; } else { text.innerHTML = \'+\'; };">-</button></td>'; select 'dbr.purehtml', '<td>

    Title goes here
    </td></tr>'; select 'dbr.purehtml', '<tr><td> </td><td><div class="hide_me">'; SELECT * FROM datawarehouse.companies LIMIT 10; select 'dbr.purehtml', '</div></td></tr></table>';

  5. adamhaeder, Member

    One more try for formatting:


    select 'dbr.title', '';
    select 'dbr.purehtml', '<table><tr><td valign="top"><button id=show1 onclick="$(\'.hide_me\').slideToggle(); text=document.getElementById(\'show1\');if (text.innerHTML == \'+\') { text.innerHTML = \'-\'; } else { text.innerHTML = \'+\'; };">-</button></td>';
    select 'dbr.purehtml', '<td>
    Title goes here
    </td></tr>';
    select 'dbr.purehtml', '<tr><td> </td><td><div class="hide_me">';
    SELECT * FROM datawarehouse.companies LIMIT 10;
    select 'dbr.purehtml', '</div></td></tr></table>';

  6. adamhaeder, Member

    I give up, I don't know how to make your forum software not try to interpret my html

  7. myDBR Team, Key Master

    Yeah, we should fix the forum as well.

    --
    myDBR Team


Reply

You must log in to post.