Advertisement
Guest User

Untitled

a guest
Sep 7th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. @model IEnumerable<HousingProject.Models.Property>
  2.  
  3. @{
  4. ViewBag.Title = "Index";
  5. WebGrid grid = new WebGrid(source: Model, canSort: false);
  6. }
  7. <style type="text/css">
  8. th, td {
  9. padding: 5px;
  10. }
  11.  
  12. th {
  13. background-color: rgb(248, 248, 248);
  14. }
  15.  
  16. #gridT, #gridT tr {
  17. border: 1px solid #0D857B;
  18. }
  19.  
  20. #subT, #subT tr {
  21. border: 1px solid #f3f3f3;
  22. }
  23.  
  24. #subT {
  25. margin: 0px 0px 0px 10px;
  26. padding: 5px;
  27. width: 95%;
  28. }
  29.  
  30. #subT th {
  31. font-size: 12px;
  32. }
  33.  
  34. .hoverEff {
  35. cursor: pointer;
  36. }
  37.  
  38. .hoverEff:hover {
  39. background-color: rgb(248, 242, 242);
  40. }
  41.  
  42. .expand {
  43. background-image: url(/Content/themes/base/images/pm.png);
  44. background-position: -22px;
  45. background-repeat: no-repeat;
  46. }
  47.  
  48. .collapse {
  49. background-image: url(/Content/themes/base/images/pm.png);
  50. background-position: -2px;
  51. background-repeat: no-repeat;
  52. }
  53. </style>
  54. <h2>Index</h2>
  55. <p>
  56. @using (Html.BeginForm("Index", "Property", FormMethod.Get))
  57. {
  58. @Html.TextBox("filter")
  59. <input type="submit" value="Search" />
  60. }
  61. </p>
  62. <p>
  63. @Html.ActionLink("Create New", "Create")
  64. </p>
  65. <table class="table">
  66. <tr>
  67. <th>
  68. @Html.DisplayNameFor(model => model.HouseNumber)
  69. </th>
  70. <th>
  71. @Html.DisplayNameFor(model => model.StreetName)
  72. </th>
  73. <th>
  74. @Html.DisplayNameFor(model => model.Town)
  75. </th>
  76. <th>
  77. @Html.DisplayNameFor(model => model.City)
  78. </th>
  79. <th>
  80. @Html.DisplayNameFor(model => model.Postcode)
  81. </th>
  82. <th>
  83. @Html.DisplayNameFor(model => model.MaxOccupancy)
  84. </th>
  85. <th></th>
  86. </tr>
  87.  
  88. @foreach (var item in Model) {
  89. <tr>
  90. <td>
  91. @Html.DisplayFor(modelItem => item.HouseNumber)
  92. </td>
  93. <td>
  94. @Html.DisplayFor(modelItem => item.StreetName)
  95. </td>
  96. <td>
  97. @Html.DisplayFor(modelItem => item.Town)
  98. </td>
  99. <td>
  100. @Html.DisplayFor(modelItem => item.City)
  101. </td>
  102. <td>
  103. @Html.DisplayFor(modelItem => item.Postcode)
  104. </td>
  105. <td>
  106. @Html.DisplayFor(modelItem => item.MaxOccupancy)
  107. </td>
  108. <td>
  109. @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
  110. @Html.ActionLink("Details", "Details", new { id=item.ID }) |
  111. @Html.ActionLink("Delete", "Delete", new { id=item.ID })
  112. </td>
  113. </tr>
  114. }
  115.  
  116. </table>
  117.  
  118. <div id="main" style="padding:25px; background-color:white;">
  119. @grid.GetHtml(
  120. htmlAttributes: new { id = "gridT", width = "700px" },
  121. columns: grid.Columns(
  122. grid.Column("HouseNumber", "House Number"),
  123. grid.Column("StreetName","Street Name"),
  124. grid.Column("Town", "Town"),
  125. grid.Column("City", "City"),
  126. grid.Column("Postcode", "Postcode"),
  127. grid.Column("MaxOccupancy", "Max Occupancy"),
  128. grid.Column("CurrentOccupancy", "Current Occupancy"),
  129. grid.Column(format: (item) =>
  130. {
  131. WebGrid subGrid = new WebGrid(source: item.CurrentTenants);
  132. return subGrid.GetHtml(
  133. htmlAttributes: new { id = "subT" },
  134. columns: subGrid.Columns(
  135. subGrid.Column("FirstName", "First Name"),
  136. subGrid.Column("Surname", "Surname"),
  137. subGrid.Column("Age", "Age"),
  138. subGrid.Column("Employer", "Employer")
  139. )
  140. );
  141. })
  142. )
  143. )
  144. </div>
  145.  
  146.  
  147.  
  148.  
  149. <script type="text/javascript">
  150.  
  151. $(document).ready(function () {
  152. var size = $("#main #gridT > thead > tr >th").size(); // get total column
  153. $("#main #gridT > thead > tr >th").last().remove(); // remove last column
  154. $("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column
  155. $("#main #gridT > tbody > tr").each(function (i, el) {
  156. $(this).prepend(
  157. $("<td></td>")
  158. .addClass("expand")
  159. .addClass("hoverEff")
  160. .attr('title', "click for show/hide")
  161. //.attr('onclick', 'toggleWebGrid()')
  162. );
  163. //Now get sub table from last column and add this to the next new added row
  164. var table = $("table", this).parent().html();
  165. //add new row with this subtable
  166. $(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>");
  167. $("table", this).parent().remove();
  168. });
  169.  
  170. //by default make all subgrid in collapse mode
  171. $("#main #gridT > tbody > tr td.expand").each(function (i, el) {
  172. $(this).toggleClass("expand collapse");
  173. $(this).parent().closest("tr").next().slideToggle(100);
  174. });
  175.  
  176. });
  177. //toggle expand and collapse
  178. $(function () {
  179. $("#main #gridT > tbody > tr td.collapse").on('click', function () {
  180. alert('test');
  181. $(this).toggleClass("expand collapse");
  182. $(this).parent().closest("tr").next().slideToggle(100);
  183. });
  184. });
  185.  
  186. </script>
  187.  
  188. <!DOCTYPE html>
  189. <html>
  190. <head>
  191. <meta charset="utf-8" />
  192. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  193. <title>@ViewBag.Title - My ASP.NET Application</title>
  194. @Styles.Render("~/Content/css")
  195. @Scripts.Render("~/bundles/modernizr")
  196.  
  197. </head>
  198. <body>
  199. <div class="navbar navbar-inverse navbar-fixed-top">
  200. <div class="container">
  201. <div class="navbar-header">
  202. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  203. <span class="icon-bar"></span>
  204. <span class="icon-bar"></span>
  205. <span class="icon-bar"></span>
  206. </button>
  207. @Html.ActionLink("Application name", "Index", "Home", null, new { @class = "navbar-brand" })
  208. </div>
  209. <div class="navbar-collapse collapse">
  210. <ul class="nav navbar-nav">
  211. <li>@Html.ActionLink("Home", "Index", "Home")</li>
  212. <li>@Html.ActionLink("About", "About", "Home")</li>
  213. <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
  214. <li>@Html.ActionLink("Properties","Index","Property")</li>
  215. </ul>
  216. @Html.Partial("_LoginPartial")
  217. </div>
  218. </div>
  219. </div>
  220. <div class="container body-content">
  221. @RenderBody()
  222. <hr />
  223. <footer>
  224. <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
  225. </footer>
  226. </div>
  227.  
  228. @Scripts.Render("~/bundles/jquery")
  229. @Scripts.Render("~/bundles/bootstrap")
  230. @RenderSection("scripts", required: false)
  231. </body>
  232. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement