Dojo creating DOM nodes dynamically - dom

I'm trying to create a custom Dojo widget for my application.
<!-- Dojo widget Template -->
<div class="newsHomeWidget">
<table width="100%" cellspacing="0" cellpadding="0">
<tbody dojoAttachPoint="newsHomeTableTbody">
<!-- May be we need to repeat this code dynamically -->
<tr>
<td class="ncmseparate">
<a class="wordwrap" dojoAttachPoint="newsHomeLink"></a>
</td>
</tr>
</tbody>
</table>
</div>
This widget is to display the list of News that I get from my service.I will get the Data in JSON format. I need to display the News Text in the anchor tag whose class is wordWrap and the link to the news as the href of this anchor tag.
Since there can be multiple news, I need to repeat for each News. I would like to do this in the best way. I can manually create the DOM for each value of News using dojo.create or dojo.place.But that requires lot of hard coding. Could you please suggest me the best way to do this? Is it possible to do that in the Widget template itself?

The simplest way would be to create a private templated widget that represents an individual news item.
for example
dojo.declare('NewsItem',[dijit._Widget,dijit._Templated],{
url:'',
headline:'',
//template abbreviated
templateString:'<tr><td><a href="${url}>${headline}</a></td></tr>'
});
Then when you retrieve the list of news from your data service, you can just iterate over each element of that array and create a new NewsItem widget and place it in the your tbody, this.newsHomeTableTbody.
var newsArray = [...]
dojo.forEach(newsArray, function(newsLink){
var newsItem = new NewsItem({
url: newsLink.url,
headline: newsLink.headline
});
newsItem.placeAt(this.newsHomeTableTbody);
},this);

Related

angular-datatables stopped working abruptly

I am using angular-datatables 13.0.1 in my angular application. I displayed a table using the following code in my UI. It was working.
Html:
<table datatable class="datatable table table-striped table-condensed h5" [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" bFilter=false>
<tfoot>
<tr>
<td colspan="8">
<div class="center-cont-block">
<mfBootstrapPaginator [rowsOnPageSet]="[50,100,500]"></mfBootstrapPaginator>
</div>
</td>
</tr>
</tfoot>
</table>
.ts file
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 50
};
dtTrigger: Subject<any> = new Subject<any>();
I used this link http://l-lin.github.io/angular-datatables/#/welcome to learn how to display an angular-datatable.
I haven't changed any of the libraries related to this. Surprisingly when I try to implement the same logic in another screen, nothing works.
Either the table developed before or new table.
Pagination is not displayed or the sorting. It is not applying any of the angular-datatables properties. When I inspect the code, many of the properties are missing few them are:
2. aria-controls

DOM element not rendering html

I have built an html table that generates dynamically from a data array. It is intended to make a menu of beers on tap in my bar. The array contains the following data: [tap_number, brewery_image, beer_name, price_for_a_pint, price_for_a_pitcher]. Therefore the array dictates that the table generate with 5 columns and 14 rows (with current data). The image data consists of an html tagged image and similarly the beer_name is tagged <h3></h3>. All the html tagged data is rendering as text. What have I done wrong? btw, using Materialize css for basic table styling. Have tried with bootstrap also - same result. Here's a snippet of the html element that the js generates:
<table class = "tabel">
<thead>
<tr>
...has <td>column name</td> X5
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><img src='[url of image]' alt=''></td>
<td><h3>[Beer_Name]</h3></td>
<td>$6</td>
<td>$10</td>
</tr>
...a bunch more rows..
</tbody>
</table>
.
So data positions 1 and 2 should be rendering according to html tag but are just appearing on the page as the text of their html. All data from the array is passed as textContent. Should I be using innerHtml? when I do, nothing at all renders. Cannot figure out what amateur mistake I've made or whether Materialize is screwing me... Thanks for any advice...
It was an amateur mistake. was using innerHtml instead of innerHTML....

colspan like feature for spring form textarea

How can I get colspan like feature in a form:textarea in spring form tag?
This is my current code:
<td><html:textarea rows="5" cols="60" path="comment" /></td>
There are total 5 columns in the table. I would like to have the label in the first column and textarea in the remaining 4 colums. How can I achieve this?
I think you don't need a "colspan-like" solution but colspan itself. Note that what you want to span is a table cell, not the textarea. Therefore, you must use the attribute on the enclosing td element.
Text areas in HTML have their own layout of rows and columns but it's completely unrelated to HTML tables. A colspan attribute on a textarea simply doesn't make sense.
Here's a piece of HTML code that does the trick.
<table>
<tr>
<td>X</td>
<td>Y</td>
<td>Z</td>
</tr>
<tr>
<td>label</td>
<td colspan="2"><textarea cols="60" rows="3"></textarea></td>
</tr>
</table>
Here's a working example on JSFiddle, styled with CSS to make the structure more visible.

Tooltip javascript disrupts following form element when "title" attribute not given

I'm using a javascript tooltip provided by jqueryTOOLS to give tool tips within a form.
For some form elements that do not require a tool tip I want to leave the title string blank, however if I do this then it causes disruption in the subsequent elements of the form - almost as if it is treating them as a tool tip: on mouseover an element with no title string it moves the following element's position to hover next to the field, then when no longer focused it disappears permanently.
My tooltip code:
$(function() {
$("#myform :input").tooltip({
position: "center right",
offset: [-2, 10],
effect: "fade",
opacity: 0.7
});
});
As you have probably guessed this tool tip is based on the 'title' attribute of a field.
After having included
<script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
in the header.
Hopefully my description of events made sense!
Thanks in advance for any help
I fixed a problem giving me the same error, but in a different context:
I had a table with two columns, both colums containing tooltips (a DIV in the corresponding TD).
<table>
<tbody>
<tr>
<td><div class="tooltip"></div></td>
<td><div class="tooltip"></div></td>
</tr>
</tbody>
</table>
When opening the tooltip in the first column, the height and width of the second column TD change (as if that TD was the tooltip).
Adding an extra empty DIV element after the tooltip DIV in the TD of the first column solved the problem.
<table>
<tbody>
<tr>
<td>
<div class="tooltip"></div>
<div></div> <!-- extra empty div -->
</td>
<td><div class="tooltip"></div></td>
</tr>
</tbody>
</table>
I figured it out:
The trigger element was defined to all inputs, so it was using the next as a tooltip in the lack of a title element.
Just a bug on the party of jqueryTOOLS but an easy solution:
replace
$("#myform :input")
with
$("#myform :input[title]")
Hope this helps someone else

Nesting dynamically displayed components in wicket

I have a need to create following kind of markup with wicket using ajax:
<table>
<tr>
<td><a>first</a></td>
<tr>
<tr>
<td>displayed/closed if first is clicked <a>open</a></td>
</tr>
<tr><td>this and following displayed/closed if above open is clicked</td></tr>
<tr><td>there may be any number of these</td></tr>
<tr>
<td>there may be any number of these as well <a>open</a></td>
</tr>
<tr>
<td>any number of these as well <a>second</a></td>
</tr>
</table>
How to use ListViews or some other wicket element to individually toggle open "inner" rows of the table. I don't want to resort to render everything and toggling visibility but really create the rows in server side only when expand is requested. The markup should also be valid xhtml (rules out arbitrary container for row groups). I know I can put multiple tbodys, but it's good enough only for one level of nesting (no .... allowed).
From Lord Torgamus' comment, the ajax tree sounds appropriate..