Dojo dijit add Div buttons dynamically - html

I am having an issue with trying to dynamically create layers that can be be built and removed with a div as a button being added upon the layer's creation. Here's how the code goes:
I am having an issue with trying to dynamically create layers that can be be built and removed with a div as a button being added upon the layer's creation. Here's how the code goes:
//build point graphics layer
graphicsLayerInfo = this._addNewExcelLayerToList(plotArray.length);
graphicsLyr = new GraphicsLayer( { id:graphicsLayerInfo.graphicsLayerID} );
this.map.add(graphicsLyr);
on(dojo.byId(graphicsLayerInfo.removeButtonID), "click" , lang.hitch(this, this._removeExcelLayer, {layerID: graphicsLayerInfo.graphicsLayerID, buttonLayerID: graphicsLayerInfo.currentLayerInfo}) );
...
and the function used to build the DIV/button
_addNewExcelLayerToList: function (pointCount) {
if (this.debugMOde) {
console.info( this.name + ' - ADD NEW EXCEL LAYER called.' );
}
this.layerCount++;
currentLayerID = 'graphicsLayer' + this.layerCount;
graphicsLayerID = this.name + '_gLyr' + this.layerCount;
removeButtonID = "removeGraphicsLayer" + this.layerCount;
this.layerList.push(currentLayerID);
var layerInfo = "Number of Features: 1 Line";
if (pointCount) {
layerInfo = "Number of Features: " + pointCount;
}
content = "<div id ='" + currentLayerID + "'" +
"style='width: 95%;" +
"height: 16px;" +
"line-height: 16px" +
"verticle-align: middle;" +
"padding: 5px;" +
"background-color: #000000;'" +
">" +
"<div style='float:left;'>" +
"<div style="float: left;" +
"width: 20px;" +
"line-height: 20px;" +
">" +
"<img src='./js/Upload/images/excel.png'" +
"style='position: absolute;" +
"top: 0;" +
"bottom: 0;" +
"margin-top: -10px;" +
"width: 20px;" +
"vertical-align: middle;'" +
"></img>" +
"</div>
"<div style='float:left;" +
"font-size: 0.9em;" +
"color: #ffffff;'" +
">" +
"Layer" + this.layerCount + ": " + layerInfo +
"</div>" +
"</div>" +
"<div id='" + removeButtonID + "'" +
"data-dojo-attach-point='" + removeButtonID + "'" +
"name='" + removeButtonID + "'" +
"id='" + removeBUttonID + "'" +
"style='float: right;" +
"width: 13px;" +
"height: 13px;" +
"cursor: pointer;" +
"border-radius: 50%;" +
"border: 2px; solid #ffffff;" +
"background-color: #ff0000;" +
"color: #ffffff;" +
"font-weight: 300;" +
"font-size: 17px;" +
"font-family: Arial, sans-serif;" +
"text-align: center;'" +
">" +
"X" +
"</div>" +
"</div>";
layerListDiv.innerHTML += content;
graphicsLayerInfo = {
removeButtonID: removeButtonID,
graphicsLayerID: graphicsLayerID,
currentLayerID: currentLayerID
}
return graphicsLayerInfo
}
and the function to remove the DIV
_removeExcelLayer: function(layerInfo) {
if (this.debugMode) {
console.info( this.name + " - REMOVE EXCEL LAYER called.");
}
this.map.removeLayer( this.map.getLayer(layerInfo.layerID) );
dojo.destroy(layerInfo.buttonLayerID);
}
It removes the layer if I create only one. If I create more than one, only the last layer created gets moved. All the other 'removeButton's don't work.
Any ideas on how to get this to remove the layers individually, per button?

Well, with the help of a coworker, I got it to work, but not with exactly a separate Event Handler. I used a domConstruct to create it's own area of influence:
domConstruct.create("div", { innerHTML: content }, layerListDiv);
instead of the straight:
layerListDiv.innerHTML += content;
Thank you for your attempts ManjunathaMuniyappa.

Related

DataTable search filter, sorting and pagination not working after fetching JSON data using Promise.fetch

I have a DataTable that display JSON data from Promise fetch. It uses loops over the JSON data and displays it in the tbody. The problem I'm having now is that, all the rows of the JSON data fetched appears in the table with no pagination, and the search filter and column sorting aren't working as well.
Here is my code snippet:
<table class="table table-striped table-hover" id="tierlist">
<thead>
<tr>
<th></th>
<th>Card Image</th>
<th>Rarity</th>
<th>Character</th>
<th>Attribute</th>
<th>R Factor Scene</th>
<th>Overall STR</th>
<th>HP</th>
<th>SP</th>
<th>ATK</th>
<th>DEF</th>
<th>HIT</th>
<th>AVO</th>
<th>LUK</th>
</tr>
</thead>
<tbody id="datarows">
</tbody>
</table>
<script type="text/javascript">
var table = $('#tierlist').DataTable({
responsive: true,
initComplete: function () {
$('.dataTables_filter input[type="search"]').css({ 'width': '50px', 'display': 'inline-block' });
}
});
// Data URL
const URL = "https://somedomain/data.json";
// Promise fetch the data and display it
fetch(URL)
.then((response) => response.json())
.then((cards) => datarows.innerHTML = displayCards(cards))
.then(table.clear().draw());
const displayCards = (cards) => {
var out = "";
var i;
for(i = 0; i<cards.length; i++) {
out += '<tr><td><img height="35" src="' + cards[i].skill + '" /></td>' +
'<td><img height="70" src="' + cards[i].cardImage + '" /></td>' +
'<td>' + cards[i].rarity + '</td>' +
'<td>' + cards[i].character + '</td>' +
'<td><img height="35" src="' + cards[i].attribute + '" /></td>' +
'<td>' + cards[i].rFactorScene + '</td>' +
'<td>' + cards[i].STR + '</td>' +
'<td>' + cards[i].HP + '</td>' +
'<td>' + cards[i].SP + '</td>' +
'<td>' + cards[i].ATK + '</td>' +
'<td>' + cards[i].DEF + '</td>' +
'<td>' + cards[i].HIT + '</td>' +
'<td>' + cards[i].AVO + '</td>' +
'<td>' + cards[i].LUK + '</td></tr>' ;
}
return out;
};
</script>
Any help would be greatly appreciated.
The data you are adding to the table in HTML is not added to the DataTable object.
The following jsfiddle solves your issue by instead of adding the fetched data to the HTML table, adding it to the DataTable object and redrawing it.
The important difference is displayed here (addData replaces displayCards):
function addData(cards){
cards.forEach(card => {
table.row.add([
'<img height="35" src="' + card.skill + '" />',
'<img height="70" src="' + card.cardImage + '" />',
card.rarity,
card.character,
'<img height="35" src="' + card.attribute + '" />',
card.rFactorScene,
card.STR,
card.HP,
card.SP,
card.ATK,
card.DEF,
card.HIT,
card.AVO,
card.LUK
]);
});
}
https://jsfiddle.net/ja03o65r/30/

Angular code inside of html strings

I am trying making the following code working:
var td = $(elem).treegrid('getPanel').find('div.datagrid-header td[field="itemtype"]');
td[0].innerHTML = td[0].innerHTML +
'<table style="width:100%;margin-top:-8px;margin-left:2px"><tr>' +
'<td style="width:18px;text-align:center">' +
'<a href="" ng-click="getFilteredAssets(filterItemType)">' +
'<img border="0" src="all_filter.png">' +
'</a>' +
'</td>' +
'</td>' +
'<td style="width:18px">' +
'<img src="assets_filter.png"/>' +
'</td>' +
'<td style="width:18px">' +
'<img src="projects_filter.gif"/>' +
'</td></tr></table>';
I am getting images into the place, but clicking on the image with ng-click specified doesn't do anything. Any idea how to make it work?
Thanks
Modified code
var element = $compile(angular.element
('<table style="width:100%;margin-top:-8px;margin-left:2px"><tr>' +
'<td style="width:18px;text-align:center">' +
'<a href="" ng-click="getFilteredAssets(filterItemType)">' +
'<img border="0" src="all_filter.png">' +
'</a>' +
'</td>' +
'</td>' +
'<td style="width:18px">' +
'<img src="assets_filter.png"/>' +
'</td>' +
'<td style="width:18px">' +
'<img src="projects_filter.gif"/>' +
'</td></tr></table>')
)(scope);
td[0].innerHTML = td[0].innerHTML + element;
Angular has no way of knowing you've added some HTML to your DOM. You should use a compile service. It will sweep HTML searching for ng-* directives and so on and apply it to current scope.
var element = $compile(angular.element('your html with ng-* directives''))(scope);
Then you can insert that element to your DOM.

How to add spaces HTML output

In the below code I want to create spaces when it is executed that is I want to see spaces
"HSC&nbsp" + txthsc.Text + "&nbspHSC" + txthscclg.Text + "
between HSC and txthsc tag so please help..
string strBody = "" +
"" +
"<div>Your name is: <b>" + txtaddress.Text + "</b></div>" +
"<div> your Gender:<b>"+txtgender.Text+"</b></div>"+
"<div> your skills:<b>" + txtskills.Text + "</b></div>" +
"<div> your experience:<b>" + txtexp.Text+ "</b></div>" +
"<div> your phno:<b>" + txtphno.Text + "</b></div>" +
"<table width=\"100%\" style=\"background-color:#cfcfcf;\"><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
"<table width=\"500%\" style=\"background-color:#cfcfcf;\"><tr><td>BBA<b>&nbsp" + txtbba.Text + "&nbsp</td><td>HSC<b>" + txtbbaclg.Text + "</td></tr></table>" +
**"<table width=\"500%\" style=\"background-color:#cfcfcf;\"><tr><td>HSC<b>&nbsp" + txthsc.Text + "&nbsp</td><td>HSC<b>" + txthscclg.Text + "</td>**</tr></table>" +
"<table width=\"500%\" style=\"background-color:#cfcfcf;\"><tr><td>SSC<b>&nbsp" + txtssc.Text + "&nbsp</td><td>HSC<b>" + txtsscclg.Text + "</td></tr></table>" +
"Resume document generated successfully."+
"</body>" +
"</html>";
i think you are missing ; from &nbsp - Correct entity is

Place one HTML input directly below another with HTML

So I have a bunch of HTML elements I'm creating dynamically. I would really like the element "imageBox" to appear directly below the "mediaBox" instead of to the left of it like it is now. Here is my code right now:
var div = document.createElement("div");
//HTML code for each element to be added with each new checkpoint
var nameBox = "<b>Checkpoint " + markerId + ":</b> <input type='text' id=" + markerId + " placeholder='Checkpoint name'>"
var descBox = "<textarea rows='4' cols='35' placeholder='Checkpoint description' id=" + markerId + "desc style='vertical-align: top;'></textarea>"
var mediaBox = "<input type='text' id='media" + markerId + "' placeholder='paste URL to YouTube video' size='23'>"
var imageBox = "<input type='text' id='image" + markerId + "' placeholder='paste URL to image' size='23'>"
var removeButton = "<button type='button' value='Remove' id='remove" + markerId + "' onClick='remove_marker(" + markerId + ")'> Remove </button>"
var undoButton = "<button type='button' value='Undo' ' style='display: none;' id='undo" + markerId + "' onClick='remove_marker(" + markerId + ")'> Undo </button>"
var removeText = "<div id='removed" + markerId + "' style='display: none;'> Removed <button type='button' value='Undo' ' style='display: none;' id='undo" + markerId + "' onClick='undo_Remove(" + markerId + ")'> Undo </button> </div>"
div.innerHTML = nameBox + descBox + mediaBox + imageBox + removeButton + removeText;
I know it is really messy and ideally I should be using CSS but I'm not right now. It shows up on my page like this:
It would be great if the image URL box could be right under the YouTube one!
Thanks so much!
For minimal re-writing, you can try wrapping the two boxes in an unordered list. If you really truly want to avoid CSS, set an inline style to remove the bullets.
div.innerHTML = (nameBox
+ descBox
+ '<ul style="list-style: none;"><li>'
+ mediaBox + "</li><li>" + imageBox
+ "</li></ul>"
+ removeButton
+ removeText);
I just inserted the relevant bits into your last line. You really really should use document.createElement and div.appendChild to create these things.

Google maps set width for InfoWindow

Hi I am using InfoWindow to get custom popup on google maps,
but I can't set it width, I tried setting it inline to wrapper tag, but it doesn't work.
In this case I need it to be 750px.
Here is jsfiddle: http://jsfiddle.net/xxast/
and here is html file: http://www.mediafire.com/view/?66dbe6xzn1mul10
Here is method that is setting InfoWindow content:
function getContent(parts, kmlEvent) {
var content = ""+
"<div id='width800' class='google-infobox-content' >" +
"<div class='image'>" +
"<img src='http://maps.google.com/maps/api/staticmap?center=" + kmlEvent.latLng.Ya + "," + kmlEvent.latLng.Za + "&zoom=13&size=150x150&maptype=roadmap&sensor=false&language=&markers=color:red|label:none|48.7758013,9.2529132' title='' width='150' height='150' >" +
"<br />" +
"<a href='https://maps.google.com/maps?sensore=true&daddr=" + kmlEvent.latLng.Za + "," + kmlEvent.latLng.Ya + "' target='_blank' >Full Google Map</a>" +
"<a href='http://maps.google.com/help/maps/directions/Somewhere' target='_blank' >Directions</a>" +
"</div>" +
"<div class='location'>" +
"<p>" + parts[0] + "</p>" +
"<p>" + parts[1] + "</p>" +
"<p>" + parts[2] + "</p>" +
"<br/>" +
"<p>" + parts[3] + "</p>" +
"</div>" +
"<div class='contact'>" +
"<p>" + parts[4] + "</p>" +
"<p>" + parts[5] + "</p>" +
"<a href='mailto:" + parts[6] + "' >" + parts[6] + "</a>" +
"<a href='" + parts[7] + "' target='_blank' >" + parts[7] + "</a>" +
"</div>" +
"<div class='others'>" +
"<p><b>Product line</b></p>" +
"<p>" + parts[8] +
"</p>" +
"</div>" +
"</div>";
return content;
}​
Updated
here is updated jsfiddle with setted maxWidth and inline width for wrapper tag, but still it doesn't work: http://jsfiddle.net/xxast/3/
there is no width in the google.maps.InfoWindowOptions object.
create a div inside your infowindow, and set its width.
the infowindow will resize to fit the internal div.
i have a working example here: http://jsfiddle.net/RASG/vA4eQ/
EDIT
some extra info:
i've found in a google group a very interesting information, written by a google employee.
Info window size is determined based on two factors:
the size of the content
the size of the map (not the browser)
to be free of this, you must implement your own kind of infowindow.
some examples here:
http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/infowindow-custom.html
http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/smartinfowindow.html
Google v3 Api comes with:
var iw = new google.maps.InfoWindow({ content: some_text, maxWidth: 200 });
More details here : Controlling the width of a Google Maps InfoWindow
Use as below in your google map script
//content = anything you like to show
var content = '<div id="content" align="center">'+
'<h1 id="firstHeading" class="firstHeading" style="margin:0;color:#ff6600;">Your Title</h1>'+
'<p style="color:#0d6585;font-weight:700;">Your Description'+
'</p>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: content,
maxWidth: 300 //your desired width
});
In infoWinfow options try to set maxWidth to 750. Also to make sure the style is not overwiten by default goole values rename google-infobox-content to something different. You may try to use a custom info window library:
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html
Make a div and set that to the infowindow using setcontent it works for sure