I am using Grails and I am currently faced with this problem.
This is the result of my html table
And this is my code from the gsp page
<tr>
<th>Device ID</th>
<th>Device Type</th>
<th>Status</th>
<th>Customer</th>
</tr>
<tr>
<g:each in = "${reqid}">
<td>${it.device_id}</td>
</g:each>
<g:each in ="${custname}">
<td>${it.type}</td>
<td>${it.system_status}</td>
<td>${it.username}</td>
</g:each>
</tr>
So the problem is, how do I format the table such that the "LHCT271 , 2 , Thomasyeo " will be shifted down accordingly? I've tried to add the <tr> tags here and there but it doesn't work.. any help please?
I think you problem is not in the view, but in the controller (or maybe even the domain). You must have some way of knowing that reqid and custname are related if they are in the same table. You must use that to construct an object that can be easily used in a g:each
You are looking for a way to mix columns and rows, and still get a nice table. I'm afraid that is not possible.
Edit
(Sorry, I just saw the last comment.)
You cannot mix two items in a g:each.
Furthermore, if the two things are not related you probably must not put them in the same table. There will be no way for you or for Grails, to know how to properly organize the information
Do you want to display the first reqid against the first custname (three fields), the second againts the second and so on? And are those collections of same length?
In such case you could try the following:
<tr>
<th>Device ID</th>
<th>Device Type</th>
<th>Status</th>
<th>Customer</th>
</tr>
<g:each var="req" in="${reqid}" status="i">
<tr>
<td>${req}</td>
<td>${custname[i].type}</td>
<td>${custname[i].system_status}</td>
<td>${custname[i].username}</td>
</tr>
</g:each>
Related
I have a table with multiple rows in the thead and DataTables doesn't like it.
Here is my code:
<TABLE ID="TBL">
<THEAD>
<TR>
<TH>COL1</TH>
<TH>COL2</TH>
<TH>COL3</TH>
<TH>COL4</TH>
<TH>COL5</TH>
<TH>COL6</TH>
</TR>
<TR>
<TH>DAT1</TH>
<TH>DAT2</TH>
<TH>DAT3</TH>
<TH>DAT4</TH>
<TH>DAT5</TH>
<TH>DAT6</TH>
</TR>
<TR>
<TH>COLA</TH>
<TH>COLB</TH>
<TH>COLC</TH>
<TH COLSPAN="2">COLD</TH>
<TH>COLF</TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD>TD1</TD>
<TD>TD2</TD>
<TD>TD3</TD>
<TD COLSPAN="2">TD4</TD>
<TD>TD6</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT>
$("#TBL").DataTable();
</SCRIPT>
I can tell dataTables does get initialized on the table but my paging, sorting, and searching controls are missing.
Is there a way to configure dataTables to work here?
I was able to get it to work somewhat by doing this:
$("#TBL").DataTable({
columns:[
{data:"COLA"},
{data:"COLB"},
{data:"COLC"},
{data:"COLD"}
{data:"COLF"}
]
)
Adding data parameters to the columns made the table work, I can search, sort, and page results. However, once it gets to 'COLD' it jumps to the upper row and wants to sort 'DAT5' and 'DAT6', so I have to set them to 'orderable:false'.
I also noticed that, while having these data declarations causes the table to work, for the most part, I seem to be unable to change the width of the columns and I'm not sure the proper syntax for doing so.
My assumption was to do something like this, where I have the 'data' declarations:
columns:[
{data:"COLA", width:"150px"},
{data:"COLB"},
{data:"COLC"},
{data:"COLD"},
{data:"COLF"}
]
But the width setting seems to have no effect. I don't know if I'm doing something wrong or if my settings aren't taking effect, simply because I have multiple rows in the THEAD and it's throwing everything off.
I also have a columnDefs section:
columnDefs:[
{
targets:[3,4],
orderable:false
}
]
This corrects the 'DAT5' and 'DAT6' from being sortable. I think I can set column widths in here as well but I'm unsure of the syntax or how to setup multiple targets/settings side by side within columnDefs.
Anyone have any advice on how to properly set this up?
Thanks
DataTables does not support <colspan> in the body of a table:
<TD COLSPAN="2">TD4</TD>
From the installation documentation:
Please also note that while DataTables supports colspan and rowspan in the table's header and footer, they are not supported in the table's tbody and must not be present.
You will need to find a different way to structure your table to avoid this restriction.
This question might be seems basic but I don't know how to return multi SQL value as one row in HTML despite its length.
This is my current table looks like:
This is an example on how it looks like after filled by value.
With this code of mine:
<div class="table">
<table>
<tr>
<th>No</th>
<th>Location 1</th>
<th>Location 2</th>
<th>Location 3</th>
<th>Price</th>
</tr>
<tr>
<td>{{$query.No}}</td>
<td>{{$query.Location_1}}</td>
<td>{{$query.Location_2}}</td>
<td>{{$query.Location_3}}</td>
<td style="text-align: left;">{{$query.Currency} {$query.Price}}</td>
</tr>
</table>
</div>
What I'm trying to do is to combine $query.Currency $query.Price $... and so on as one row, without any endline.
Desired Output:
So, I finally found out how to solve the breaking space for SQL return variables in my problem.
If you guys ever encountered such problem, you can fix it by separating variables. Here is how:
<td style="text-align: left;">{{$query.Currency}} {{$query.Price}}</td>
I have the following table in html using AngularJS:
<table id="searchTable">
<thead>
<tr>
<th>Index</th>
<th>Observation</th>
<th>Reported By</th>
<th>Verified By</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="observation in observations| filter:searchText">
<th> {{$index + 1}} </th>
<th>{{observation.clinicalType}}</th>
<th>{{observation.reportedBy}}</th>
<th>{{observation.verifiedBy}}</th>
<th>{{observation.reportedDate}}</th>
</tr>
</tbody>
</table>
In the columns "Observations", "Reported By", "Verified By", and "Date", it is possible to have the string "NULL". I was wondering if there is a quick and easy way in CSS to color each instance of "NULL" in red in all of the four columns? I've been stuck there for quite some time.
Personally I'd suggest doing this in Jquery. You could look for all <th> elements that contain "NULL" and change them to red by doing the following...
$(document).ready(function() {
$("th:contains('NULL')").css("color", "red");
});
JSFiddle: https://jsfiddle.net/97oqnuyx/
EDIT: Because you've graciously accepted my answer, however it actually doesn't seem to solve the issue in your specific case, I feel I should make sure that I'm not spreading misinformation in the event people find this.
While my answer above will work in many cases, this is probably not the way to go if you're using Angular. In that event, you're looking for a solution more like this one, which OP linked to in a comment above.
I have three tables which are using using different variables for displaying the data.
Basic structure of the table
<table>
<thead>
<tr>
<th ng-repeat="var in array2"><i ng-show="array3[$index]=0"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="var in variable">
<td ng-repeat="var1 in var">{{var1.position}}</td>
</tr>
</tbody>
</table>
All the three tables are using different arrays for variable, array2 and array3. Is there any way I don't have to write the code thrice and I can loop the code for three tables.
Please suggest changes in data structures only when there are no other possible HTML solution to change it.
You need to check for directives, for instance <my-table-directive datas="array1"></my-table-directive>
This directive will hold the logic and templaces and you'll pass a variable to define the content.
I have a table where elements can have child elements with the very same attributes, like:
ITEM ATTRIBUTE 1 ATTRIBUTE 2
item value value
sub value value
sub value value
item value value
From this I've created a markup like this:
<table>
<thead>
<tr>
<th>ITEM</th>
<th>ATTRIBUTE 1</th>
<th>ATTRIBUTE 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>item</td>
<td>value</td>
<td>value</td>
</tr>
<tr>
<td colspan=3>
<table>
<tbody>
<tr>
<td>sub</td>
<td>value</td>
<td>value</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>item</td>
<td>value</td>
<td>value</td>
</tr>
</tbody>
</table>
My questions are now:
Is this the best semantic solution?
Is another approach better suited? If so, which is the recommended way?
Is the table header in charge for both tables or do I have to create a new one (maybe with visibility: hidden for the nested table?
Is this the best semantic solution?
Not really. While the act of nesting an element A within another element B can be used to indicate that A is a child of B, that isn't what you're doing here: you're nesting the table within a completely different row, so there's no implication of a parent-child relationship between A and B.
By creating a cell that spans all the columns in the table and then building another table inside that with the same number of columns, you're also effectively saying "these are some other columns, that don't relate to the ones in the outer table".
You can see the implied (lack of) relationship between the columns by adding a border to the cells in your example above:
Obviously you can fix that with CSS, but the unstyled rendering of a piece of HTML is often a good guide to its semantics.
Is another approach better suited? If so, which is the recommended way?
There's no standard way to represent hierarchical relationships between rows of a table in HTML. Cribbing from an answer I gave to a similar question, though, you can do it with extra classes, ids and data- attributes:
<table>
<thead>
<tr>
<th>ITEM</th>
<th>ATTRIBUTE 1</th>
<th>ATTRIBUTE 2</th>
</tr>
</thead>
<tbody>
<tr id=100>
<td>item</td>
<td>value</td>
<td>value</td>
</tr>
<tr id=110 data-parent=100 class=level-1>
<td>sub</td>
<td>value</td>
<td>value</td>
</tr>
<tr id=200>
<td>item</td>
<td>value</td>
<td>value</td>
</tr>
</tbody>
</table>
The parent-child relationship won't be visible in an unstyled rendering (there's no other way you could make it so without adding extra content, as far as I can see), but there are enough hooks to add the CSS required:
.level-1 > td:first-child {
padding-left: 1em;
}
... which results in this:
With a little javascript, you could also use the id and data-parent attributes to set things up so that e.g. hovering over a row causes its parent to be highlighted.
Is the table header in charge for both tables, or do I have to create a new one?
In your proposed solution, creating a single cell that spans all columns and then building another table inside it means that there's no implied relationship between the header cells and those of your "child" row. Obviously my suggested solution above doesn't have that problem.
This is W3C's recommendation:
At the current time, those who want to ensure consistent support across Assistive
Technologies for tables where the headers are not in the first row/column may want
to use the technique for complex tables H43: Using id and headers attributes to
associate data cells with header cells in data tables. For simple tables that have
headers in the first column or row we recommend the use of the th and td elements.
you can lock at this post: Best way to construct a semantic html table
hope that will help you to get your answer
Talking about semantics requires us to have more time than to find an answer for your question.
But for a whole point, this link should help you. That page contains all the information you may be interested in. Interestingly unlike normal 'declarative' spec w3c writes, it has 'suggestive' writing about the question in this context. You may wish to read right from the start.
I think putting the children in a separate table is the wrong way to go. Nested tables are not like nested lists; they don't carry that same semantic hierarchy. It seems everything should be within the same table if it all lists the same information.
For example, if your table had the headers
REGION POPULATION AREA
then you could have item1 = Earth, item2 = France, item3 = Paris... and it wouldn't really matter if France were a child of Earth or if Paris were a child of France; you'd still be better off keeping it all in one table and not trying to do a parent/child relationship other than in CSS styling.
If your table is really not comprehensible without someone knowing that parent/child relationship, could you give an example of the table data so I can better understand how to structure it?