Expand and Collapse on button click

Posted by kumar on Stack Overflow See other posts from Stack Overflow or by kumar
Published on 2010-04-29T19:54:13Z Indexed on 2010/04/29 20:17 UTC
Read the original article Hit count: 439

Filed under:

Please this is not a duplicate thread do consider this one..thanks..

<script type="text/javascript">
    $(document).ready(function() {
        $('#tmpOpen').click(function() {
            var value = $("#tmpOpen").attr("value");
            if (value == "Expand") {
                document.getElementById("tmpOpen").value = "Collapse";
                loadAll();
            }
            else {
                document.getElementById("tmpOpen").value = "Expand";
                loadAll();
            }
        });
     function loadAll() {
                $('#Grid tr[role="row"] td a').each(function(row) {
                if ($('#CGrid tr[role="row"] td.hasClass(sgcollapsed) a')) {
                   $(this).click();
                   }
                   else if ($('#Grid tr[role="row"] td.hasClass(sgexpanded) a')) {
                        return false;
                    }
                });
            }
    });


</script>
<div>
  <input type="submit" id="tmpOpen"  value="Expand" 
                     style="width:145px; height:30px;"/>
</div>

First time the grid is loading with all the user data..at very firsst row each use can exapdn the grid to see subgird using + sign,, when use clicks + sign I am expanding the row to show subgrid,

above code is working at very frist time when I click expand button its expanding all the rows and collpase its colaapsing allt he rows perfectly,

but user open any row to see subgrid,, after clicking the expand button opened row will closing and closing rows will be opening.. exactly its doing opposite?

can anyone sujjest me what is this cause in the code? thanks

© Stack Overflow or respective owner

Related posts about jQuery