There is a "Weekly Monitoring tool" on the intranet I'm working on that displays the following information (supposedly) in a grid : the company, the employee (name), his expected work time, and his current weekly activity.
The Data is saved and filtered week by week, it's all sent to my WeeklyMonitoring.aspx view.
The issue is that I can't seem to find a way to display it as a grid, cleanly, separating each information to make it easier to read.
Here is the relevant part of my View :
<table width="300" border="1" cellpadding="0" cellspacing="0">
<tr>
<th>Company</th>
<th>Employee</th>
<th>Expected Time</th>
<th>Activity</th>
</tr>
<%
int i = 0;
foreach (var name in ViewBag.Names)
{
if ((string)ViewBag.Names[i] != null)
{ %>
<td><%= (string)ViewBag.Company[i]%></td>
<td><%= (string)ViewBag.Names[i]%></td>
<td> --- </td>
<td><%= (string)ViewBag.RecTime[i]%></td>
<%} %>
<%i++; %>
<%
}
%>
</table>
It does display it as a board, separating the information by spaces, how may I create a clean looking grid as it is supposed to be?
JQuery DataTables in an awesome plugin for this and it's very simple to use. First, add the plugin:
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
then Format the table properly:
<table id ="table_id" class="display">
<thead>
<tr>
<th>Company</th>
<th>Employee</th>
<th>Expected Time</th>
<th>Activity</th>
</tr>
</thead>
<%
int i = 0;
foreach (var name in ViewBag.Names)
{
<tr>
if ((string)ViewBag.Names[i] != null)
{ %>
<td><%= (string)ViewBag.Company[i]%></td>
<td><%= (string)ViewBag.Names[i]%></td>
<td> --- </td>
<td><%= (string)ViewBag.RecTime[i]%></td>
<%} %>
<%i++; %>
</tr>
<% } %>
Now, apply the DataTable properties on the table:
<script>
$(document).ready(function () {
$('#table_id').DataTable();
});
</script>
and see the charm.
Related
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%# Import Namespace="PagedList.Mvc" %>
<%# Import Namespace="PagedList" %>
<!DOCTYPE html>`enter code here`
<html>
<head runat="server">
<title>ViewPage1</title>
<link href="../../Public/css/PagedList.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<table class="tableEmptyStyle">
<tr>
</tr>
</table>
<table>
<tr>
<th>
Code
</th>
<th>
Name
</th>
</tr>
<%
foreach (var item in ViewBag.OnePageDivisions)
{ %>
<tr>
<td>
<%: item.Code %>
</td>
<td>
<%: item.Name %>
</td>
</tr>
<% Html.PagedListPager((IPagedList)ViewBag.OnePageDivisions, page => Url.Action("Index", new { page = page }), PagedListRenderOptions.PageNumbersOnly); %>
<% } %>
</table>
Then from the controller I am getting the list and
ViewBag.OnePageDivisions = allList
I am able to get the list and display it,
the problem is the page numbers below are not showing.
The CSS, "PagedList.css" was taken from the package. Any help is appreciated
I am using MVC 3, PagedList 1.15.0.0 and PagedList.Mvc 3.18.0.0
Change
<% Html.PagedListPager((IPagedList)ViewBag.OnePageDivisions, page => Url.Action("Index", new { page = page }), PagedListRenderOptions.PageNumbersOnly); %>
To
<%: Html.PagedListPager((IPagedList)ViewBag.OnePageDivisions, page => Url.Action("Index", new { page = page }), PagedListRenderOptions.PageNumbersOnly) %>
My problem is in view...Please give me new view which suits my database and action.
My details table:
Passing request id using html action link:
#Html.ActionLink(item.Request_ID, "Details",new { requestid = item.Request_ID },null )
clicking on the link we should get details corresponding to the link from database.
Action method:
public ActionResult Details(string requestid)
{
var entities = new EmployDBEntities1();
var detailsModel = entities.Details.Single(e => e.Id == requestid);
return View(detailsModel);
//return View(entities.Details.ToList());
}
Hope my problem is returning view and designing view. My requirement is I want details for particular id and should display them in the below designed view. I am able to check the ids in var details model and then I have to read remaining fields from databse and disply the fields in my view.I am notable to do it. Please help me.
View:
model IEnumerable<Approvals.Models.Detail>
#{
ViewBag.Title = "Details";
//Layout = "~/Views/Shared/_Layout.cshtml";
}
#section Header {
#Html.ActionLink("Back", "PendingRequests", "Account", null, new { data_icon = "arrow-l", data_rel = "back" })
<h1>#ViewBag.Title</h1>
#Html.ActionLink("Log Off", "LogOff")
}
<head>
<link href="~/StyleSheet1.css" rel="stylesheet" type="text/css" />
</head>
<div data-role="collapsible" data-theme="b" data-content-theme="b">
<h3>Employee Details</h3>
<table class="td3">
#foreach (var item in Model) {
<tr>
<td>Employee ID</td>
<td>#Html.Encode(item.EmpID)</td>
</tr>
<tr>
<td>Short ID</td>
<td>
#Html.Encode(item.ShortID)
</td>
</tr>
<tr>
<td>Grade</td>
<td>#Html.Encode(item.Grade)</td>
</tr>
<tr>
<td>Vertical</td>
<td>#Html.Encode(item.Vertical)</td>
</tr>
<tr>
<td>Vertical Head</td>
<td>#Html.Encode(item.VerticalHead)</td>
</tr>
<tr>
<td>L1 Manager</td>
<td>#Html.Encode(item.L1_Manager)</td>
</tr>
<tr>
<td>L2 Manager</td>
<td>#Html.Encode(item.L2_Mnager)</td>
</tr>
<tr>
<td>CostCentre</td>
<td>#Html.Encode(item.CostCentre)</td>
</tr>
}
</table>
</div>
model Approvals.Models.Detail
#{
ViewBag.Title = "Details";
//Layout = "~/Views/Shared/_Layout.cshtml";
}
#section Header {
#Html.ActionLink("Back", "PendingRequests", "Account", null, new { data_icon = "arrow-l", data_rel = "back" })
<h1>#ViewBag.Title</h1>
#Html.ActionLink("Log Off", "LogOff")
}
<head>
<link href="~/StyleSheet1.css" rel="stylesheet" type="text/css" />
</head>
<div data-role="collapsible" data-theme="b" data-content-theme="b">
<h3>Employee Details</h3>
<table class="td3">
<tr>
<td>Employee ID</td>
<td>#Html.Encode(Model.EmpID)</td>
</tr>
<tr>
<td>Short ID</td>
<td>
#Html.Encode(Model.ShortID)
</td>
</tr>
<tr>
<td>Grade</td>
<td>#Html.Encode(Model.Grade)</td>
</tr>
<tr>
<td>Vertical</td>
<td>#Html.Encode(Model.Vertical)</td>
</tr>
<tr>
<td>Vertical Head</td>
<td>#Html.Encode(Model.VerticalHead)</td>
</tr>
<tr>
<td>L1 Manager</td>
<td>#Html.Encode(Model.L1_Manager)</td>
</tr>
<tr>
<td>L2 Manager</td>
<td>#Html.Encode(Model.L2_Mnager)</td>
</tr>
<tr>
<td>CostCentre</td>
<td>#Html.Encode(Model.CostCentre)</td>
</tr>
</table>
</div>
Instead of var type for detailsModel object give type what is bound to view i.e. IEnumerable of Approvals.Models.Detail in "Details" action.
your view name should match action name if not supplied in return View(). else return View("xxx", detailsModel ) in "Details" action.
I have a simple web page where for each row of data, I can pop up a jQuery UI dialog with the details of that row. Since there can be multiple rows in the sub-query a table is the best choice. The result is that I get an empty dialog box, and the table contained in that div (the one for the dialog) appears at the bottom of the page, whether the row is clicked to activate the dialog. Everything else works perfectly, the event for the click, the dialog popup, the passing of the right id for the div, all perfect.
But the dang table (the one inside the dialog, with the class of 'inner-table') appears at the bottom of the page, right off the bat.
The HTML is created in Groovy, with the HTMLMarkupBuilder, and the resulting HTML looks like the following:
<html>
<head>
<title>NAS Execution Groovy Servlet</title>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery-ui-1.8.23.custom.min.js'></script>
<script type='text/javascript' src='js/jquery.dataTables.min.js'></script>
<script type='text/javascript' src='js/executions.js'></script>
<link rel='stylesheet' type='text/css' href='css/jquery.dataTables_themeroller.css'></link>
<link rel='stylesheet' type='text/css' href='css/jquery-ui.css'></link>
<link rel='stylesheet' type='text/css' href='css/nas.css'></link>
</head>
<body>
<div id='results' class='execution-results'>
<p id='rpt-header'>
<span class='rpt-header-txt'>Backup Schedule Report for </span>
<span class='rpt-header-asset'>ret2w089n1t1</span>
</p>
<table id='nas-table'>
<thead>
<tr class='table-header'>
<th class='hidden'>Backup ID</th>
<th>Schedule Name</th>
<th>Backup Product</th>
<th>Size Mb</th>
<th>Start Time</th>
<th>Duration</th>
<th>Expiration Date</th>
<th>Mon 17</th>
</tr>
</thead>
<tbody>
<tr class='row'>
<td class='hidden'>12345678</td>
<td class='row-data'>null</td>
<td class='row-data'>Product One</td>
<td id='size-mb' class='row-data'>601.31</td>
<td class='row-data'>00:09:03</td>
<td class='row-data'>158 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<tr class='row'>
<td class='hidden'>23456789</td>
<td class='row-data'>PolicyName</td>
<td class='row-data'>Product Two</td>
<td id='size-mb' class='row-data'>995.92</td>
<td class='row-data'>20:09:00</td>
<td class='row-data'>191 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<div id='dialog-23456789' class='details-dialog'>
<table class='inner-table'>
<thead>
<tr>
<th>JOB_TYPE_NAME</th>
<th>VENDOR_STATUS_NAME</th>
<th>KILOBYTES</th>
</tr>
</thead>
<tbody>
<tr>
<td>Incr Backup</td>
<td>Successful</td>
<td>1019821</td>
</tr>
</tbody>
</table>
</div>
</tbody>
</table>
</div>
</body>
</html>
The jQuery for this is pretty simple; it uses the id from the row clicked on, and pops up a dialog window. That works fine, but the table that is contained in that div is actually at the bottom of the screen, even before anything is clicked:
$(document).ready(function() {
$('#nas-table').dataTable( {
"bJQueryUI": true,
"aaSorting": [[4, 'asc']]
} );
$('.row').live("click", function(){
var target = $(this);
var backupId = $(this).children(":first").html();
var thisId = '#dialog-' + backupId;
$(thisId).dialog(
{
title: "Backup Job Detail",
width: 800,
height: 450
}
);
$(thisId).dialog("open");
$(thisId).dialog("widget").position({
my: 'left top',
at: 'left bottom',
of: target
});
});
} );
At first, I thought the Groovy HTMLMarkupBuilder was outputting the DOM before everything happened, but when I do a view source, copy it to a file, and open the file in my browser, I get the same result.
I would appreciate any help with this. I asked this question earlier, in case you want to complain about that, but I had to follow up some other potential issues in the Groovy code, which I resolved. This example is more complete, and represents exactly what my code will do.
Brian
The problem is that you have a div nested within a table outside of a TR and TD, which will cause the rendering and DOM to be a bit wrong. If you adjust the html so that it resembles something like this it will work:
<div id='results' class='execution-results'>
<p id='rpt-header'>
<span class='rpt-header-txt'>Backup Schedule Report for </span>
<span class='rpt-header-asset'>ret2w089n1t1</span>
</p>
<table id='nas-table'>
<thead>
<tr class='table-header'>
<th class='hidden'>Backup ID</th>
<th>Schedule Name</th>
<th>Backup Product</th>
<th>Size Mb</th>
<th>Start Time</th>
<th>Duration</th>
<th>Expiration Date</th>
<th>Mon 17</th>
</tr>
</thead>
<tbody>
<tr class='row'>
<td class='hidden'>12345678</td>
<td class='row-data'>null</td>
<td class='row-data'>Product One</td>
<td id='size-mb' class='row-data'>601.31</td>
<td class='row-data'>00:09:03</td>
<td class='row-data'>158 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<tr class='row'>
<td class='hidden'>23456789</td>
<td class='row-data'>PolicyName</td>
<td class='row-data'>Product Two</td>
<td id='size-mb' class='row-data'>995.92</td>
<td class='row-data'>20:09:00</td>
<td class='row-data'>191 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
</tbody>
</table>
<div id='dialog-23456789' class='details-dialog' style="display:none;">
<table class='inner-table'>
<thead>
<tr>
<th>JOB_TYPE_NAME</th>
<th>VENDOR_STATUS_NAME</th>
<th>KILOBYTES</th>
</tr>
</thead>
<tbody>
<tr>
<td>Incr Backup</td>
<td>Successful</td>
<td>1019821</td>
</tr>
</tbody>
</table>
</div>
</div>
The trick is to move the div outside of the parent table and also you need to set the display:none on the details table or it will be shown when the page is rendered.
This snippet is from my admin. I have a description field next to an image, and a demo of how'd that look below it.
Right now it works after a page refresh but i'd like it to work asynchronously using AJAX, so as the user types it updates the demo below the textarea.
#This is where you update the field
<tr><th>Description</th><td><%= f.text_area(:description) %></td></tr>
<tr><th>Demo</th>
<td>
<% if #org.images.present? %>
<table border="0">
<tr>
<td>
<%= featured_image_tag(#org, :type => 'organization') %>
</td>
<td style="vertical-align:top;padding-top:5px;padding-left:5px;">
<span class="font-avebook"><%= #org.description %> </span><br>
</td>
</tr>
</table>
<% else %>
You need to assoicate an image first before seeing the demo!
<% end %>
</td>
</tr>
To get the text to appear directly below at the same time as you're writing you need to use a jQuery Keyup event to submit the data. However, submitting the data after each keyup is not the best idea. If you want to get that effect, why don't you just do the whole thing with jQuery without actually saving the data. You can append the contents of the input to the element beside the image after each keyup. I've made a little demo below.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type="text" id="copy_text">
<div id="mirror_paragraph"></div>
<script>
$("#copy_text").keyup(function () {
var txt = $("#copy_text").val();
$("#mirror_paragraph").html(txt);
});
</script>
</body>
</html>
Adapted to your code:
<tr>
<th>Description</th>
<td><%= f.text_area(:description), :id => "copy_text" %></td>
</tr>
<tr>
<th>Demo</th>
<td>
<% if #org.images.present? %>
<table border="0">
<tr>
<td>
<%= featured_image_tag(#org, :type => 'organization') %>
</td>
<td style="vertical-align:top;padding-top:5px;padding-left:5px;">
<span class="font-avebook" id="mirror_paragraph"><%= #org.description %> </span><br>
</td>
</tr>
</table>
<% else %>
You need to assoicate an image first before seeing the demo!
<% end %>
</td>
</tr>
<script>
$("#copy_text").keyup(function () {
var txt = $("#copy_text").val();
$("#mirror_paragraph").html(txt);
});
</script>
I have following view
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Tables <%=ViewData["RetriverName"] %></h2>
<%using (Html.BeginForm("ResfreshSelectedTables", "Home"))
{ // begin form%>
<table id="MyTable">
<thread>
<tr>
<th style="width: 150px; text-align:center"><input type="checkbox" id="SelectAll" />Select All..</th>
</tr>
<tr>
<th style="width:20px; text-align:right">ID</th>
<th style="width:40px">Base Table</th>
<th style="width:50px">Table</th>
<th style="width:280px">Description</th>
</tr>
</thread>
<tbody>
<% int i = 0;
foreach (var item in Model)
{ %>
<tr id="row<%= i.ToString() %>">
<td align="center" style="padding: 0 0 0 0">
<%= Html.CheckBox("selections[" + i.ToString() + "].IsSelected", item.IsSelected)%>
<%= Html.Hidden("selections[" + i.ToString() + "].ID", item.id)%>
<%= Html.Hidden("selections[" + i.ToString() + "].BaseTable", item.baseTable)%>
<%= Html.Hidden("selections[" + i.ToString() + "].Name", item.NAME)%>
</td>
<td style="text-align:right"><%=Html.Encode(item.id)%></td>
<td><%= Html.Encode(item.baseTable)%></td>
<td><%=Html.Encode(item.NAME)%></td>
<td><%=Html.Encode(item.Description) %></td>
</tr>
<% i++;
} %>
</tbody>
</table>
<p>
<input type="submit" value="saving" />
</p>
<% }//end form %>
<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
// Select All Checkboxes
$(document).ready(function() {
$('#SelectAll').click(function() {
var newValue = this.checked;
$('input:checkbox').not('input:hidden').each(function() {
// alert(this.id+newValue );
this.checked = newValue;
});
});
});
</script>
</asp:Content>
How do I postback selected checkboxes to the controller ?
Try adding a hidden field for the index of the selected item, as shown in one of Phil Haack's blog posts. You'd then receive the collection as a list of that type on the controller. This will ensure that the collection gets items with both the checked and unchecked checkboxes, in the correct order on the server side. Filter the list to choose only those with IsSelected having value true.
<%= Html.Hidden("selections.Index", i) %>