I have a partial view that is loading a data table. When I debug, I'm able to step into the partial view and watch the data table get built. Everything seems to work fine except nothing happens when the Data Table completes. It's as if I'm missing the last step to actually get the HTML to render my results.
I saw a post stating to use $('#datatable').DataTable(); in a function, but that did not seem to work. Also another post suggesting to use $('#partialViewDataTable').DataTable().ajax.reload(); in a function, but I couldn't get that to work either. How can I display the Data Table values in a Partial View correctly?
UPDATE:
I was able to get it to work using the .load() JQuery method. More .load() method information can be found here. I also had conflicting JQuery libraries which was the majority of my problem. I added .load() function which calls my GetAssociateResults method in my TOSAdjustmentcontroller. I have updated my original question to reflect the solution that worked for me.
View
<div class="card-content">
<div class="card-body">
<div id="dvAssociateResults">
#{Html.RenderPartial("AssociateResultsPartialView", Model);}
</div>
</div>
</div>
$("#pcmId").on("change", function () {
$("#dvAssociateResults").load('#(Url.Action("GetAssociateResults", "TOSAdjustment", null, Request.Url.Scheme))?pcmSelected=' + encodeURIComponent($('#pcmId').val()));
})
Partial View
<table class="table table-striped table-bordered dom-jQuery-events compact" id="table_id">
<thead class="navbar-dark navbar-dark bg-blue-grey white">
<tr>
<th>
Associate
</th>
<th>
SSO
</th>
<th>
PCM
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model.get_employees_under_mgr_result)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.AgentName)
</td>
<td>
#Html.DisplayFor(modelItem => item.AgentSSOn)
</td>
<td>
#Html.DisplayFor(modelItem => item.MgrName)
</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<th>
Associate
</th>
<th>
SSO
</th>
<th>
PCM
</th>
</tr>
</tfoot>
</table>
Related
i am working on a project where a clerk like professional will make/edit classes time table for educational institute.
so in a day-period cell there are many drop-downs for selecting teacher, classroom/lab, batch of students, subject etc.
and this whole combination of values can be repeated many places in the grid.
so i want to post a single value combining all these 4-5 values through POST data in FORM for that cell location.
what approach should i use?
EDIT:
Oh! Yes, i am actually using PHP and angularjs and this is sample code in html
<table border="1" width="90%" height="90%" style="margin:10px">
<thead>
<tr>
<td>
Day
</td>
<td ng-repeat="hour in chours">
{{hour.name}}
<br>
{{hour.stime}}--{{hour.etime}}
<br>
<input type="checkbox" ng-model="hour.noclass" /> No class {{hour.noclass}}
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="day in weekdays">
<td>
{{day.name}}
</td>
<td ng-repeat="hour in day.hours">
<div ng-show="hour.noclass=='false'" name="cell[{{day.name}}][{{hour.name}}][]">
<select name="cars">
<option ng-model="dd" ng-repeat="sub in subjects">{{sub.name}}</option>
</select>
{{dd}}
</div>
</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
and this is in js file
var App = angular.module('tteditApp',[]);
App.controller('editCtrl', function($scope){
$scope.chours=[
{'name':'1','stime':'800','etime':'855','noclass':'true'},
{'name':'2','stime':'855','etime':'950','noclass':'true'},
{'name':'3','stime':'800','etime':'855','noclass':'false'},
{'name':'4','stime':'800','etime':'855','noclass':'false'},
{'name':'5','stime':'800','etime':'855','noclass':'false'},
{'name':'6','stime':'800','etime':'855','noclass':'false'},
{'name':'7','stime':'800','etime':'855','noclass':'false'},
{'name':'8','stime':'800','etime':'855','noclass':'false'},
{'name':'9','stime':'800','etime':'855','noclass':'false'},
{'name':'10','stime':'800','etime':'855','noclass':'false'}];
$scope.subjects=[{'name':'CLOUD'},{'name':'CC'},{'name':'ISS'},{'name':'DCT'},{'name':'DMW'},{'name':'VLSI'},{'name':'SEMINAR'},{'name':'PROJECT'},{'name':'WEB DEV'}];
$scope.weekdays=[{'name':'Monday','hours':$scope.chours},{'name':'Tuesday','hours':$scope.chours},
{'name':'Wednesday','hours':$scope.chours},{'name':'Thursday','hours':$scope.chours},{'name':'Friday','hours':$scope.chours}
,{'name':'Saturday','hours':$scope.chours}];
});
I have a simple ASP.NET MVC3 index page which holds more than 11k items. I have buttons for operation links as an extra. The code is like follows:
<table class="list">
<tr>
<th></th>
<th>
Name
</th>
<th>
Code
</th>
<th>
Explanation
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
<a href="#Url.Action("Edit", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/edit.png")" alt="Edit" title="Edit" />
</a>
<a href="#Url.Action("Details", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/info.png")" alt="Details" title="Details"/>
</a>
<a href="#Url.Action("Delete", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/delete.png")" alt="Delete" title="Delete"/>
</a>
</td>
<td width="600px">
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Code)
</td>
<td>
#Html.DisplayFor(modelItem => item.Explanation)
</td>
</tr>
}
There's no problem opening it with any other browsers inluding Chrome and Firefox, but in IE8 first it tries running, then locks permanently. I don't expect a good performance from IE, but how can I make it work? Small tips for just saving the day are greatly appreciated. I tried to give static width to a varying sized column, for example.
UPDATE: I deleted the image links' column and it worked; even faster with tables, rather than div-ul-li setup I tried before.
I recommend you if you have bulk data, override the paging on the table. Send your data to table part by part with JSON. In every next or prev buttons clicking send new list to table.
I am tried to create table structure with header,body,footer in listview which works fine.
But in footer which is in layouttemplate, i tried to add below code which gives error.
<LayoutTemplate>
<table class="sampletable" cellpadding="0" cellspacing="0">
<thead class="tableheader">
<tr>
<th>
<a>Samples </a>
</th>
</tr>
</thead>
<tbody class="tablebody">
<tr id="itemplaceHolder" runat="server">
</tr>
</tbody>
<tfoot class="tablefooter">
<tr>
<td>
<a href='<%:Page.GetRouteUrl("samplelist",null) %>'>more sample</a>
</td>
</tr>
</tfoot>
</table>
</LayoutTemplate>
Is it not allowed to place in layouttemplate?
The error is
"The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."
Use the 'RouteUrlExpressionBuilder'.
Link
Properly documented at MSDN.
I have a partial view like this:
#model List<user>
#foreach (var user in Model)
{
<tr>
<td>#user.name</td>
<td>...</td>
</tr>
}
And get an error like this:
Validation (HTML5): Element 'tr' cannot be nested within element 'tr'.
It's annoying me more than it should, but I want to get rid of it. Installing Web Standards Update didn't help. Any ideas?
Edit
This is the main view:
<table>
<thead>
<tr>
<th>#i18n.name</th>
<th>...</th>
</tr>
</thead>
<tbody id="results">
#Html.Partial("list_rows", #Model.users)
</tbody>
</table>
This is the generated HTML:
<table>
<thead>
<tr>
<th>naam</th>
<th>...</th>
</tr>
</thead>
<tbody id="results">
<tr>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
Edit Pulling the entire page through the W3C validator gives
This document was successfully checked as HTML5!
This error appears when you open a <tr> element before you loop through your model. So far the code you postet is correct and free of errors.
Just make sure that your code looks something like this:
<table>
#foreach (var user in Model)
{
<tr>
<td>#user.name</td>
<td>...</td>
</tr>
}
</table>
It seems like you already have an open tr tag in which you are trying to add more tr tags. If you already have tr tags in your table, just make sure they are all closed before the loop starts:
<tr>..</tr>
I had my webpage validated for xhtml transitional till I added this table (see below). Since then it doesn't validate and says "
document type does not allow element "tfoot" here <tfoot>
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).
One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error)."
Any ideas as what is happening? I checked for any opened and not closed tags but did not find any so I don't know what else is wrong.
<table>
<caption>
My first table, Anna
</caption>
<thead>
<tr>
<th>
June
</th>
<th>
July
</th>
<th>
August
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Data 1
</td>
<td>
Data 2
</td>
<td>
Data 3
</td>
<td>
Data 4
</td>
</tr>
<tr>
<td>
Data a
</td>
<td>
Date b
</td>
<td>
Data c
</td>
<td>
Data d
</td>
</tr>
<tfoot>
<tr>
<td>
Result1
</td>
</tr>
</tfoot>
</tbody>
</table>
You've got the <tfoot> at the end of the table. It should be between the <thead> and the <tbody>. It will appear at the bottom, but it's coded at the top. One of the original ideas is that as a large table loaded, the heading and footer would be visible quickly, with the rest filling in (esp. useful if the body was scrollable between them). It hasn't quite worked out like that in practice, but it does make more sense if you know that.
In the DTD it lists:
<!ELEMENT table (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>
That is, optional caption, then zero-or-more col or colgroup, then optional thead, then optional tfoot, then at least one tbody or tr.
UPDATE: Note that HTML 5 now allows one to put the <tfoot> at the end of the table, instead of before the first <tbody> (or the first <tr> that isn't in a <thead>, <tfoot> or <tbody> and hence in a single implicit <tbody>). As such the code in the question would now be considered valid. The older approach is also still valid, and probably advisable.
The tfoot element should be outside of the tbody element, like this:
<table>
<caption>
My first table, Anna
</caption>
<thead>
<tr>
<th>
June
</th>
<th>
July
</th>
<th>
August
</th>
</tr>
</thead>
<tfoot>
<tr>
<td>
Result1
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
Data 1
</td>
<td>
Data 2
</td>
<td>
Data 3
</td>
<td>
Data 4
</td>
</tr>
<tr>
<td>
Data a
</td>
<td>
Date b
</td>
<td>
Data c
</td>
<td>
Data d
</td>
</tr>
</tbody>
Here is a small example of the correct nesting for those who need it.
<table>
<caption></caption>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<td></td>
</tr>
</tfoot>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>