Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
To expand/collapse row details, but would like to tweak it to collapse any already open details when a new row is clicked, so that only one row's details are ever shown at a time. Without recursing through the entire table, is there an efficient way of doing this? I was thinking of storing the expanded row's ID in a variable, and just toggling the row when a new row is clicked and updating the variable with the new row's ID, but I haven't had enough coffee yet this morning to figure out how to make this work.

IF YOU HAVE ANY DOUBT SEE THIS EXAMPLE:


"http://www.modeltraintracker.com/sandbox/items.php"
i want this type in mvc 5
Posted
Updated 13-Jul-14 23:40pm
v2
Comments
jo.him1988 14-Jul-14 7:04am    
hi you can make your own javascript function for this first you have to create img tag with diffrent id and set onclick method to your javascript function with current id( as your new row id here) set current row to toggle while all other to up
here i have made a @country.CountryID as a increment id start from 1

yes you can also use accordion control of ajax or you can also use jquery ui accordion.

but i have made(try :))how accordian code write on javascript


hope this will help you


happy coding :) :) :)

You can do so by just wrapping your row in an accordion control of ajax or you can also use jquery ui accordion.

By choosing one of the above given ways you can display one row at a time and hide all others.

An accordion is the one which has several panes but displays the content of only one selected pane at a time.
 
Share this answer
 
v2
@model List<testmvc4.data.country>

@{
    ViewBag.Title = "SearchView";
    
}



<script type="text/javascript" src="../../Scripts/jquery-1.7.1.min.js">

</script>
<script type="text/javascript">
   
    function toggal(value,counts) {
        $(document).ready(function () {
            //for expand clicked row
            $("#panel-" + value).slideToggle();
            for (i = 0; i &lt; counts; i++) {
                if (i != value) {
                // for all other to hide
                    $("#panel-" + i).slideUp();
                } 
            }
        });
    }
    
</script>

<h2>SearchView</h2>
<table style="width:60%">
<tr>
<th>Country ID</th>
<th>Country Name</th>
</tr>
@foreach (var country in Model)
{
  <tr>
  <td>
  <img id="flip @country.CountryID" onclick=" return toggal(@country.CountryID,@Model.Count);" style="padding:5px;&lt;br mode=" hold=" /&gt;text-align:center;&lt;br mode=" runat="server" src="../../Images/bullet.png" height="20" width="20" />

div id="panel-@country.CountryID" style="padding:50px;display:none; &lt;br mode=" hold=" /&gt;text-align:center;&lt;br mode=">Hello world!</div>
  </td>
  <td>@country.CountryID</td>
  <td>@country.CountryName</td>
</tr>
    }
</table>
}</testmvc4.data.country>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900