How to create a link inside of dynatree on a custom node? - dynatree

I am using dynatree and added a custom hoverover menu with links to pages; however, I cannot figure out why my links to the other pages aren't firing..
Here is my code for the tree:
<script type="text/javascript">
$(function() {
$("#catTree2").dynatree({
checkbox: false,
selectMode: 3,
children: [
{title: "First Year", isFolder: true,
children: [
{title: "ESUNRS 110 (Intro to Nursing I)"},
{title: "ESUNRS 112 (Intro to Nursing II)"},
{title: "ESUNRS 120 (Pharmacology in Nursing)"} ]},
{title: "Second Year", isFolder: true,
children: [
{title: "ESUNRS 200 (Seminar I)"},
{title: "ESUNRS 201 (Seminar II)"},
{title: "ESUNRS 220 (Nursing of Adults I)"},
{title: "ESUNRS 221 (Nursing of Adults II)"},
{title: "ESUNRS 224 (Child and Mental Health Nursing I)"},
{title: "ESUNRS 225 (Child and Mental Health Nursing II)"} ]},
{title: "Third Year", isFolder: true,
children: [
{title: "ESUNRS 300 (Seminar III)"},
{title: "ESUNRS 320 (Maternal-Newborn Nursing)"},
{title: "ESUNRS 322 (Management in Nursing)", isFolder: true,
children: [
{title: "Example Questions"} ]}, ]},
],
onCustomRender: function (node) {
var html = "<span class='dynatree-title' href='#'>";
html += "<span class='td'>";
html += node.data.title;
html += "</span>";
html += "<span class='td'>";
html += "<ul id='options'>";
html += "<li class='image'>";
html += "<img src='/Icons/cog.png' alt='Options Menu'/>";
html += "<ul class='optionsMenu' style='top:20px;right:-119px;'>";
html += "<li>";
html += "<a href='#' class='createFolderOpen'>";
html += "New Folder";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='#' class='editFolderOpen'>";
html += "Edit Folder";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='#' class='deleteFolderOpen'>";
html += "Delete Folder";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='#' class='shareFolderOpen'>";
html += "Share Folder";
html += "</a>";
html += "</li>";
html += "<li>";
html += "Create New Question";
html += "<ul style='top:136px;right:-120px;'>";
html += "<li>";
html += "<a href='http://74.39.250.15/questions_create.asp'>";
html += "Multiple Choice";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='questions_create_tf.asp'>";
html += "True/False";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='questions_create_essay.asp'>";
html += "Essay";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='questions_create_fitb.asp'>";
html += "Fill in the Blank";
html += "</a>";
html += "</li>";
html += "</ul>";
html += "</li>";
html += "<li>";
html += "<a href='questions_import.asp'>";
html += "Import Questions";
html += "</a>";
html += "</li>";
html += "<li>";
html += "<a href='#' class='exportQuestionsOpen'>";
html += "Export Questions";
html += "</a>";
html += "</li>";
html += "</ul>";
html += "</li>";
html += "</ul>";
html += "</span>";
html += "<span class='td'>";
html += "55";
html += "</span>";
html += "</span>";
return html;
},
//children: treeData,
onSelect: function(select, node) {
// Get a list of all selected nodes, and convert to a key array:
var selKeys = $.map(node.tree.getSelectedNodes(), function(node) {
return node.data.key;
});
$("#echoSelection4").text(selKeys.join(", "));
// Get a list of all selected TOP nodes
var selRootNodes = node.tree.getSelectedNodes(true);
// ... and convert to a key array:
var selRootKeys = $.map(selRootNodes, function(node) {
return node.data.key;
});
$("#echoSelectionRootKeys4").text(selRootKeys.join(", "));
$("#echoSelectionRoots4").text(selRootNodes.join(", "));
},
onDblClick: function(node, event) {
node.toggleSelect();
},
onKeydown: function(node, event) {
if (event.which == 32) {
node.toggleSelect();
return false;
}
}
});
});
</script>
why do my links not work?

A bit old but I use :
onCustomRender: function(node) {
var html = "<a href='xxxxx?FileId=" + node.data.key + "'>";
html += xxxxxxxxxxxx+"</a>";
return html;
}

Related

Piranha CMS - Custom block won't save

Very new to Piranha and Vue, but not to .Net Core. Trying to get my arms around how to create custom blocks. I've created a new block, attempting to marry the HtmlBlock and ImageBlock:
using Piranha.Extend;
using Piranha.Extend.Blocks;
using Piranha.Extend.Fields;
namespace YR.Models.Piranha.Blocks
{
[BlockType(Name = "Card", Category = "Content", Icon = "fas fa-address-card", Component = "card-block")]
public class CardBlock : Block
{
public ImageField ImgBody { get; set; }
public SelectField<ImageAspect> Aspect { get; set; } = new SelectField<ImageAspect>();
public HtmlField HtmlBody { get; set; }
public override string GetTitle()
{
if (ImgBody != null && ImgBody.Media != null)
{
return ImgBody.Media.Filename;
}
return "No image selected";
}
}
}
If I omit the Component property in the BlockTypeAttribute, the block works, saves the image and content to draft and updates the site perfectly when published. For the full experience in the manager, I tried to also build a Vue component that just combined both the html-block.vue and image-block.vue components.
Here's what I have for the Vue component:
Vue.component("card-block", {
props: ["uid", "toolbar", "model"],
data: function () {
return {
imgBody: this.model.imgBody.value,
htmlBody: this.model.htmlBody.value
};
},
methods: {
clear: function () {
// clear media from block
},
onBlur: function (e) {
this.model.htmlBody.value = e.target.innerHTML;
},
onChange: function (data) {
this.model.htmlBody.value = data;
},
remove: function () {
this.model.imgBody.id = null;
this.model.imgBody.media = null;
},
select: function () {
if (this.model.imgBody.media != null) {
piranha.mediapicker.open(this.update, "Image", this.model.imgBody.media.folderId);
} else {
piranha.mediapicker.openCurrentFolder(this.update, "Image");
}
},
update: function (media) {
if (media.type === "Image") {
this.model.imgBody.id = media.id;
this.model.imgBody.media = media;
// Tell parent that title has been updated
this.$emit('update-title', {
uid: this.uid,
title: this.model.imgBody.media.filename
});
} else {
console.log("No image was selected");
}
}
},
computed: {
isEmpty: function () {
return {
htmlBody: piranha.utils.isEmptyHtml(this.model.htmlBody.value),
imgBody: this.model.imgBody.media == null
}
},
mediaUrl: function () {
if (this.model.imgBody.media != null) {
return piranha.utils.formatUrl(this.model.imgBody.media.publicUrl);
} else {
return piranha.utils.formatUrl("~/manager/assets/img/empty-image.png");
}
}
},
mounted: function () {
piranha.editor.addInline(this.uid, this.toolbar, this.onChange);
this.model.imgBody.getTitle = function () {
if (this.model.imgBody.media != null) {
return this.model.imgBody.media.filename;
} else {
return "No image selected";
}
};
},
beforeDestroy: function () {
piranha.editor.remove(this.uid);
},
template:
"<div class='block-body has-media-picker rounded' :class='{ empty: isEmpty }'>" +
" <img class='rounded' :src='mediaUrl'>" +
" <div class='media-picker'>" +
" <div class='btn-group float-right'>" +
" <button :id='uid' class='btn btn-info btn-aspect text-center' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>" +
" <i v-if='model.aspect.value === 0' class='fas fa-cog'></i>" +
" <img v-else :src='iconUrl'>" +
" </button>" +
" <div class='dropdown-menu aspect-menu' :aria-labelledby='uid'>" +
" <label class='mb-0'>{{ piranha.resources.texts.aspectLabel }}</label>" +
" <div class='dropdown-divider'></div>" +
" <a v-on:click.prevent='selectAspect(0)' class='dropdown-item' :class='{ active: isAspectSelected(0) }' href='#'>" +
" <img :src='piranha.utils.formatUrl('~/manager/assets/img/icons/img-original.svg')'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(1)' class='dropdown-item' :class='{ active: isAspectSelected(1) }' href='#'>" +
" <img :src='piranha.utils.formatUrl('~/manager/assets/img/icons/img-original.svg')'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(2)' class='dropdown-item' :class='{ active: isAspectSelected(2) }' href='#'>" +
" <img :src='piranha.utils.formatUrl('~/manager/assets/img/icons/img-original.svg')'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(3)' class='dropdown-item' :class='{ active: isAspectSelected(3) }' href='#'>" +
" <img :src='piranha.utils.formatUrl('~/manager/assets/img/icons/img-original.svg')'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(4)' class='dropdown-item' :class='{ active: isAspectSelected(4) }' href='#'>" +
" <img :src='piranha.utils.formatUrl('~/manager/assets/img/icons/img-original.svg')'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" </div>" +
" <button v-on:click.prevent='select' class='btn btn-primary text-center'>" +
" <i class='fas fa-plus'></i>" +
" </button>" +
" <button v-on:click.prevent='remove' class='btn btn-danger text-center'>" +
" <i class='fas fa-times'></i>" +
" </button>" +
" </div>" +
" <div class='card text-left'>" +
" <div class='card-body' v-if='isEmpty'>" +
" " +
" </div>" +
" <div class='card-body' v-else>" +
" {{ model.body.media.filename }}" +
" </div>" +
" </div>" +
"</div>" +
" <div contenteditable='true' :id='uid' spellcheck='false' v-html='htmlBody' v-on:blur='onBlur'></div>" +
"</div>"
});
It's basically a meld of the two Vue components that I found in the repo on GitHub, but I've massaged it a little to get it to not spit out errors in the DevTools console. I'll revisit those items if I can just get past saving it.
So, here are my questions for #tidyui or anyone who's successfully implemented something like this:
Am I going about this the right way? I simply want three columns, each column would contain my CardBlock which has a picture and a blurb of content under it, but I want the CardBlock to be a single unit (kind of like a Bootstrap Card). Is there already a way to do this without creating my own block? I researched nesting BlockGroups, but quickly found out that it isn't possible.
If I'm on the right track, I need help with the error I'm getting when I attempt to save the draft. The error is identical to Save ImageBlock error #1117, which appears to have been fixed in 8.2. I'm on 8.4.2.
I absolutely LOVE the idea of a CMS built for .Net Core, and Piranha blows away the CMS I created for myself. I just need a little push in the right direction, please, I've been at this for most of the day.
Thanks in advance,
D
Just in case this helps someone. Turns out I did a poor job merging the two blocks together. Chalk this one up to inexperience with both Piranha and Vue.js. I was mixing the code from the docs with the code in the repo. Don't do that - the docs are understandably still a bit behind. I'm not throwing stones at the developers, I really dig what they've created and will continue to put forth the effort to use it proficiently.
Below is what I came up with for the Vue component. There are probably still a few tweaks to be made to separate the Image-Block and Html-Block code better, but it now works, saves, and does not throw errors in the console.
/*global
piranha
*/
Vue.component("card-block", {
props: ["uid", "toolbar", "model"],
data: function () {
return {
imgBody: this.model.imgBody.value,
htmlBody: this.model.htmlBody.value
};
},
methods: {
clear: function () {
// clear media from block
},
onBlur: function (e) {
this.model.htmlBody.value = e.target.innerHTML;
},
onChange: function (data) {
this.model.htmlBody.value = data;
},
select: function () {
if (this.model.imgBody.media != null) {
piranha.mediapicker.open(this.update, "Image", this.model.imgBody.media.folderId);
} else {
piranha.mediapicker.openCurrentFolder(this.update, "Image");
}
},
remove: function () {
this.model.imgBody.id = null;
this.model.imgBody.media = null;
},
update: function (media) {
if (media.type === "Image") {
this.model.imgBody.id = media.id;
this.model.imgBody.media = {
id: media.id,
folderId: media.folderId,
type: media.type,
filename: media.filename,
contentType: media.contentType,
publicUrl: media.publicUrl,
};
// Tell parent that title has been updated
this.$emit('update-title', {
uid: this.uid,
title: this.model.imgBody.media.filename
});
} else {
console.log("No image was selected");
}
},
selectAspect: function (val) {
this.model.aspect.value = val;
},
isAspectSelected(val) {
return this.model.aspect.value === val;
}
},
computed: {
isImgEmpty: function (e) {
return this.model.imgBody.media == null;
},
isHtmlEmpty: function () {
return piranha.utils.isEmptyHtml(this.model.htmlBody.value);
},
mediaUrl: function () {
if (this.model.imgBody.media != null) {
return piranha.utils.formatUrl(this.model.imgBody.media.publicUrl);
} else {
return piranha.utils.formatUrl("~/manager/assets/img/empty-image.png");
}
},
iconUrl: function () {
if (this.model.aspect.value > 0) {
if (this.model.aspect.value === 1 || this.model.aspect.value === 3) {
return piranha.utils.formatUrl("~/manager/assets/img/icons/img-landscape.svg");
} else if (this.model.aspect.value == 2) {
return piranha.utils.formatUrl("~/manager/assets/img/icons/img-portrait.svg");
} else if (this.model.aspect.value == 4) {
return piranha.utils.formatUrl("~/manager/assets/img/icons/img-square.svg");
}
}
return null;
}
},
mounted: function () {
piranha.editor.addInline(this.uid, this.toolbar, this.onChange);
this.model.getTitle = function () {
if (this.model.imgBody.media != null) {
return this.model.imgBody.media.filename;
} else {
return "No image selected";
}
};
},
beforeDestroy: function () {
piranha.editor.remove(this.uid);
},
template:
"<div class='block-body has-media-picker rounded' :class='{ empty: isImgEmpty }'>" +
" <div class='image-block'>" +
" <img class='rounded' :src='mediaUrl'>" +
" <div class='media-picker'>" +
" <div class='btn-group float-right'>" +
" <button :id='uid + \"-aspect\"' class='btn btn-info btn-aspect text-center' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>" +
" <i v-if='model.aspect.value === 0' class='fas fa-cog'></i>" +
" <img v-else :src='iconUrl'>" +
" </button>" +
" <div class='dropdown-menu aspect-menu' :aria-labelledby='uid + \"-aspect\"'>" +
" <label class='mb-0'>{{ piranha.resources.texts.aspectLabel }}</label>" +
" <div class='dropdown-divider'></div>" +
" <a v-on:click.prevent='selectAspect(0)' class='dropdown-item' :class='{ active: isAspectSelected(0) }' href='#'>" +
" <img :src='piranha.utils.formatUrl(\"~/manager/assets/img/icons/img-original.svg\")'><span>{{ piranha.resources.texts.aspectOriginal }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(1)' class='dropdown-item' :class='{ active: isAspectSelected(1) }' href='#'>" +
" <img :src='piranha.utils.formatUrl(\"~/manager/assets/img/icons/img-landscape.svg\")'><span>{{ piranha.resources.texts.aspectLandscape }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(2)' class='dropdown-item' :class='{ active: isAspectSelected(2) }' href='#'>" +
" <img :src='piranha.utils.formatUrl(\"~/manager/assets/img/icons/img-portrait.svg\")'><span>{{ piranha.resources.texts.aspectPortrait }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(3)' class='dropdown-item' :class='{ active: isAspectSelected(3) }' href='#'>" +
" <img :src='piranha.utils.formatUrl(\"~/manager/assets/img/icons/img-landscape.svg\")'><span>{{ piranha.resources.texts.aspectWidescreen }}</span>" +
" </a>" +
" <a v-on:click.prevent='selectAspect(4)' class='dropdown-item' :class='{ active: isAspectSelected(4) }' href='#'>" +
" <img :src='piranha.utils.formatUrl(\"~/manager/assets/img/icons/img-square.svg\")'><span>{{ piranha.resources.texts.aspectSquare }}</span>" +
" </a>" +
" </div>" +
" <button v-on:click.prevent='select' class='btn btn-primary text-center'>" +
" <i class='fas fa-plus'></i>" +
" </button>" +
" <button v-on:click.prevent='remove' class='btn btn-danger text-center'>" +
" <i class='fas fa-times'></i>" +
" </button>" +
" </div>" +
" <div class='card text-left'>" +
" <div class='card-body' v-if='isImgEmpty'>" +
" " +
" </div>" +
" <div class='card-body' v-else>" +
" {{ model.imgBody.media.filename }}" +
" </div>" +
" </div>" +
" </div>" +
" </div>" +
" <br />" +
" <div class='html-block'>" +
" <div class='block-body border rounded' :class='{ empty: isHtmlEmpty }' >" +
" <div contenteditable='true' :id='uid' v-html='htmlBody' v-on:blur='onBlur'></div> " +
" </div>" +
" </div>" +
"</div>"
});
I'd still love to get some confirmation that I didn't do all of this unnecessarily. If there's a better way to have done it, please don't hold back.

how to fix column width in IE, chrome for datatables

I have a table in datatables. problem is some columns have a lot of text squeezed into a small column. it does not seem to readjust the width. Issue here is the table is wider than the container it is within so i do not want to give it a fixed width. i want it to by dynamically adjustable but not squeeze large text into small columns.
The column is remarks
https://jsfiddle.net/shorif2000/aa9wnhd6/
var datax = [{"ID":"10837","COMMS_MATRIX_ID":"729","FILENAME":"INC000023081620-Stage_Universal_Communication_Matrix1.xlsx","CMLINE":"22","SRC":"x.x.x.x","SRC_NET":"x.x.x.x\/25","SRC_ZONE":"s.v.l","SRC_SECZONE":"s","SRC_NETZONE":"v","SRC_LOCZONE":"l","DST":"x.x.x.x","DST_NET":"x.x.x.x\/27","DST_ZONE":"s.v.l","DST_SECZONE":"s","DST_NETZONE":"v","DST_LOCZONE":"l","SPA":"Deny","SPN":"Flow is denied by the security zoning policy","RPA":"Permit","RPN":"Flow is permitted within the same routing domain","FPA":"Permit","FPN":"Flow is permitted using an acceptable port","STATUS":"To implement","PROTOCOL":"TCP","PORTS":"80","NAT_DIR":null,"NAT_IP":null,"ENVIRONMENT":"none","SERVICE_GROUPING":null,"TRACK":"1.5","REMARKS":"EXTERNAL REVERSE PROXY 1 TO MID-TIER LOAD BALANCER","DROW":"9","SRC_DESC":"001","DST_DESC":null,"REMEDY_INC":null,"CREATED_BY":"UddinS2","UPDATED_BY":"UddinS2","SRC_SOCT1":"x","SRC_SOCT2":"232","SRC_SOCT3":"163","SRC_SOCT4":"4","SRC_EOCT1":"x","SRC_EOCT2":"232","SRC_EOCT3":"163","SRC_EOCT4":"4","SRC_CIDR":"32","SRC_NET_SOCT1":"x","SRC_NET_SOCT2":"232","SRC_NET_SOCT3":"163","SRC_NET_SOCT4":"0","SRC_NET_EOCT1":"x","SRC_NET_EOCT2":"232","SRC_NET_EOCT3":"163","SRC_NET_EOCT4":"127","SRC_NET_CIDR":"25","DST_SOCT1":"139","DST_SOCT2":"47","DST_SOCT3":"171","DST_SOCT4":"29","DST_EOCT1":"139","DST_EOCT2":"47","DST_EOCT3":"171","DST_EOCT4":"29","DST_CIDR":"32","DST_NET_SOCT1":"139","DST_NET_SOCT2":"47","DST_NET_SOCT3":"171","DST_NET_SOCT4":"0","DST_NET_EOCT1":"139","DST_NET_EOCT2":"47","DST_NET_EOCT3":"171","DST_NET_EOCT4":"31","DST_NET_CIDR":"27","NAT_TO":null,"NAT_TO_SOCT1":null,"NAT_TO_SOCT2":null,"NAT_TO_SOCT3":null,"NAT_TO_SOCT4":null,"NAT_TO_EOCT1":null,"NAT_TO_EOCT2":null,"NAT_TO_EOCT3":null,"NAT_TO_EOCT4":null,"NAT_FROM":null,"NAT_FROM_SOCT1":null,"NAT_FROM_SOCT2":null,"NAT_FROM_SOCT3":null,"NAT_FROM_SOCT4":null,"NAT_FROM_EOCT1":null,"NAT_FROM_EOCT2":null,"NAT_FROM_EOCT3":null,"NAT_FROM_EOCT4":null,"ECT":"None","DUPLICATES":null,"CMIDS":null,"TS_CREATED":"14-Dec-17 11:04:20"},{"ID":"10838","COMMS_MATRIX_ID":"729","FILENAME":"INC000023081620-Stage_Universal_Communication_Matrix1.xlsx","CMLINE":"23","SRC":"x.x.x.x","SRC_NET":"x.x.x.x\/25","SRC_ZONE":"s.v.l","SRC_SECZONE":"C2","SRC_NETZONE":"VOD","SRC_LOCZONE":"RAT","DST":"x.x.x.x","DST_NET":"139.47.171.0\/27","DST_ZONE":"s.v.l","DST_SECZONE":"TP","DST_NETZONE":"VOD","DST_LOCZONE":"RAT","SPA":"Deny","SPN":"Flow is denied by the security zoning policy","RPA":"Permit","RPN":"Flow is permitted within the same routing domain","FPA":"Permit","FPN":"Flow is permitted using an acceptable port","STATUS":"To implement","PROTOCOL":"TCP","PORTS":"80","NAT_DIR":null,"NAT_IP":null,"ENVIRONMENT":"none","SERVICE_GROUPING":null,"TRACK":"1.5","REMARKS":"EXTERNAL REVERSE PROXY 2 TO MID-TIER LOAD BALANCER","DROW":"9","SRC_DESC":"008","DST_DESC":null,"REMEDY_INC":null,"CREATED_BY":"UddinS2","UPDATED_BY":"UddinS2","SRC_SOCT1":"195","SRC_SOCT2":"232","SRC_SOCT3":"163","SRC_SOCT4":"11","SRC_EOCT1":"195","SRC_EOCT2":"232","SRC_EOCT3":"163","SRC_EOCT4":"11","SRC_CIDR":"32","SRC_NET_SOCT1":"195","SRC_NET_SOCT2":"232","SRC_NET_SOCT3":"163","SRC_NET_SOCT4":"0","SRC_NET_EOCT1":"195","SRC_NET_EOCT2":"232","SRC_NET_EOCT3":"163","SRC_NET_EOCT4":"127","SRC_NET_CIDR":"25","DST_SOCT1":"139","DST_SOCT2":"47","DST_SOCT3":"171","DST_SOCT4":"29","DST_EOCT1":"139","DST_EOCT2":"47","DST_EOCT3":"171","DST_EOCT4":"29","DST_CIDR":"32","DST_NET_SOCT1":"139","DST_NET_SOCT2":"47","DST_NET_SOCT3":"171","DST_NET_SOCT4":"0","DST_NET_EOCT1":"139","DST_NET_EOCT2":"47","DST_NET_EOCT3":"171","DST_NET_EOCT4":"31","DST_NET_CIDR":"27","NAT_TO":null,"NAT_TO_SOCT1":null,"NAT_TO_SOCT2":null,"NAT_TO_SOCT3":null,"NAT_TO_SOCT4":null,"NAT_TO_EOCT1":null,"NAT_TO_EOCT2":null,"NAT_TO_EOCT3":null,"NAT_TO_EOCT4":null,"NAT_FROM":null,"NAT_FROM_SOCT1":null,"NAT_FROM_SOCT2":null,"NAT_FROM_SOCT3":null,"NAT_FROM_SOCT4":null,"NAT_FROM_EOCT1":null,"NAT_FROM_EOCT2":null,"NAT_FROM_EOCT3":null,"NAT_FROM_EOCT4":null,"ECT":"None","DUPLICATES":null,"CMIDS":null,"TS_CREATED":"14-Dec-17 11:04:20"},{"ID":"10839","COMMS_MATRIX_ID":"729","FILENAME":"INC000023081620-Stage_Universal_Communication_Matrix1.xlsx","CMLINE":"24","SRC":"x.x.x.x","SRC_NET":"x.x.x.x\/25","SRC_ZONE":"s.v.l","SRC_SECZONE":"s","v":"l","SRC_LOCZONE":"s","DST":"x.x.x.x","DST_NET":"x.x.x.0\/27","DST_ZONE":"s.v.l","DST_SECZONE":"TP","DST_NETZONE":"VOD","DST_LOCZONE":"RAT","SPA":"Deny","SPN":"Flow is denied by the security zoning policy","RPA":"Permit","RPN":"Flow is permitted within the same routing domain","FPA":"Permit","FPN":"Flow is permitted using an acceptable port","STATUS":"To implement","PROTOCOL":"TCP","PORTS":"80","NAT_DIR":null,"NAT_IP":null,"ENVIRONMENT":"none","SERVICE_GROUPING":null,"TRACK":"1.5","REMARKS":"INTERNAL REVERSE PROXY 1 TO MID-TIER LOAD BALANCER","DROW":"9","SRC_DESC":"-209-207","DST_DESC":null,"REMEDY_INC":null,"CREATED_BY":"UddinS2","UPDATED_BY":"UddinS2","SRC_SOCT1":"195","SRC_SOCT2":"233","SRC_SOCT3":"209","SRC_SOCT4":"207","SRC_EOCT1":"195","SRC_EOCT2":"233","SRC_EOCT3":"209","SRC_EOCT4":"207","SRC_CIDR":"32","SRC_NET_SOCT1":"195","SRC_NET_SOCT2":"233","SRC_NET_SOCT3":"209","SRC_NET_SOCT4":"128","SRC_NET_EOCT1":"195","SRC_NET_EOCT2":"233","SRC_NET_EOCT3":"209","SRC_NET_EOCT4":"255","SRC_NET_CIDR":"25","DST_SOCT1":"139","DST_SOCT2":"47","DST_SOCT3":"171","DST_SOCT4":"29","DST_EOCT1":"139","DST_EOCT2":"47","DST_EOCT3":"171","DST_EOCT4":"29","DST_CIDR":"32","DST_NET_SOCT1":"139","DST_NET_SOCT2":"47","DST_NET_SOCT3":"171","DST_NET_SOCT4":"0","DST_NET_EOCT1":"139","DST_NET_EOCT2":"47","DST_NET_EOCT3":"171","DST_NET_EOCT4":"31","DST_NET_CIDR":"27","NAT_TO":null,"NAT_TO_SOCT1":null,"NAT_TO_SOCT2":null,"NAT_TO_SOCT3":null,"NAT_TO_SOCT4":null,"NAT_TO_EOCT1":null,"NAT_TO_EOCT2":null,"NAT_TO_EOCT3":null,"NAT_TO_EOCT4":null,"NAT_FROM":null,"NAT_FROM_SOCT1":null,"NAT_FROM_SOCT2":null,"NAT_FROM_SOCT3":null,"NAT_FROM_SOCT4":null,"NAT_FROM_EOCT1":null,"NAT_FROM_EOCT2":null,"NAT_FROM_EOCT3":null,"NAT_FROM_EOCT4":null,"ECT":"None","DUPLICATES":null,"CMIDS":null,"TS_CREATED":"14-Dec-17 11:04:20"},{"ID":"10840","COMMS_MATRIX_ID":"729","FILENAME":"INC000023081620-Stage_Universal_Communication_Matrix1.xlsx","CMLINE":"25","SRC":"x.x.x.x","SRC_NET":"x.x.x.x\/25","SRC_ZONE":"s.v.l","SRC_SECZONE":"E1","SRC_NETZONE":"VOD","SRC_LOCZONE":"RAT","DST":"x.x.x.x","DST_NET":"139.47.171.0\/27","DST_ZONE":"s.v.l","DST_SECZONE":"TP","DST_NETZONE":"VOD","DST_LOCZONE":"RAT","SPA":"Deny","SPN":"Flow is denied by the security zoning policy","RPA":"Permit","RPN":"Flow is permitted within the same routing domain","FPA":"Permit","FPN":"Flow is permitted using an acceptable port","STATUS":"To implement","PROTOCOL":"TCP","PORTS":"80","NAT_DIR":null,"NAT_IP":null,"ENVIRONMENT":"none","SERVICE_GROUPING":null,"TRACK":"1.5","REMARKS":"INTERNAL REVERSE PROXY 2 TO MID-TIER LOAD BALANCER","DROW":"9","SRC_DESC":"-209-208","DST_DESC":null,"REMEDY_INC":null,"CREATED_BY":"UddinS2","UPDATED_BY":"UddinS2","SRC_SOCT1":"195","SRC_SOCT2":"233","SRC_SOCT3":"209","SRC_SOCT4":"208","SRC_EOCT1":"195","SRC_EOCT2":"233","SRC_EOCT3":"209","SRC_EOCT4":"208","SRC_CIDR":"32","SRC_NET_SOCT1":"195","SRC_NET_SOCT2":"233","SRC_NET_SOCT3":"209","SRC_NET_SOCT4":"128","SRC_NET_EOCT1":"195","SRC_NET_EOCT2":"233","SRC_NET_EOCT3":"209","SRC_NET_EOCT4":"255","SRC_NET_CIDR":"25","DST_SOCT1":"139","DST_SOCT2":"47","DST_SOCT3":"171","DST_SOCT4":"29","DST_EOCT1":"139","DST_EOCT2":"47","DST_EOCT3":"171","DST_EOCT4":"29","DST_CIDR":"32","DST_NET_SOCT1":"139","DST_NET_SOCT2":"47","DST_NET_SOCT3":"171","DST_NET_SOCT4":"0","DST_NET_EOCT1":"139","DST_NET_EOCT2":"47","DST_NET_EOCT3":"171","DST_NET_EOCT4":"31","DST_NET_CIDR":"27","NAT_TO":null,"NAT_TO_SOCT1":null,"NAT_TO_SOCT2":null,"NAT_TO_SOCT3":null,"NAT_TO_SOCT4":null,"NAT_TO_EOCT1":null,"NAT_TO_EOCT2":null,"NAT_TO_EOCT3":null,"NAT_TO_EOCT4":null,"NAT_FROM":null,"NAT_FROM_SOCT1":null,"NAT_FROM_SOCT2":null,"NAT_FROM_SOCT3":null,"NAT_FROM_SOCT4":null,"NAT_FROM_EOCT1":null,"NAT_FROM_EOCT2":null,"NAT_FROM_EOCT3":null,"NAT_FROM_EOCT4":null,"ECT":"None","DUPLICATES":null,"CMIDS":null,"TS_CREATED":"14-Dec-17 11:04:20"}];
var buttons = {
text: 'Download',
className: 'btn btn-primary dropdown-toggle',
action: function ( e, dt, node, config ) {
}
};
var routing_analysis = false;
var servicedesign = false;
var techops = false;
var statuses = ['To implement','In progress','Implemented', 'To remove'];
var ccpProjectUser = false;
var frozen = false;
$(document).ready( function () {
var table = $('#dt-comms_matrix').DataTable({
dom: "<'row'<'col-md-6'l><'col-md-6'Bf>>" +
"<'row'<'col-md-6'><'col-md-6'>>" +
"<'row'<'col-md-12't>><'row'<'col-md-6'i><'col-md-6'p>>",
"bAutoWidth": false,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"iDisplayLength": 25,
"processing": true,
"language": {
"loadingRecords": '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i> Loading...',
"processing": '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i> Processing...'
},
stateSave: true,
"order": [[ 2, "asc" ],[1,'asc']],
data: datax,
buttons: [
buttons,
'colvis'
],
"autoWidth": false,
"columnDefs": [
{
targets: [0,3],
"searchable": false,
"sortable": false
},
{
"targets": [ 4 ],
"searchable": false,
"sortable": false
},
{
"targets": [ 18 ],
"width": '100px'
},
],
"columns": [
{
"data": function(row,type,val,meta){
var error = false;
var html = '<div style="width:85px">';
html += '<input type="checkbox" name="select_download['+row.ID+']" data-value="'+row.ID+'" autocomplete="off" data-toggle="popover" data-content="Select to add flow to download" data-trigger="hover" />';
if(ccpProjectUser && !frozen){
html += '<span data-toggle="modal" data-target="#myModalForm" title="Click to edit row" data-row="'+meta.row+'" data-cmid="'+row.COMMS_MATRIX_ID+'" data-id="'+row.ID+'" data-src="'+row.SRC+'" data-src_desc="'+row.SRC_DESC+'" data-dst="'+row.DST+'" data-dst_desc="'+row.DST_DESC+'" data-protocol="'+row.PROTOCOL+'" data-ports="'+row.PORTS+'" data-environment="'+row.ENVIRONMENT+'" data-service_grouping="'+row.SERVICE_GROUPING+'" data-track="'+row.TRACK+'" data-remarks="'+row.REMARKS+'">';
html += '<a class="btn btn-sm btn-info" data-toggle="popover" data-content="Click to edit row" data-trigger="hover" href="javascript:void(0)"><i class="fa fa-pencil" aria-hidden="true"></i></a>';
html += '</span>';
html += '<a class="btn btn-sm btn-danger delete_comms_matrix_flow" data-toggle="popover" data-content="Delete flow" data-trigger="hover" href="javascript:void(0)" data-id="'+row.ID+'"><i class="fa fa-trash" aria-hidden="true"></i></a>';
}
if(error){
return html + '</div>';
}else{
html += '<button type="button" class="btn btn-sm btn-default btn_commsmatrix_ect" data-toggle="popover" data-trigger="hover" data-content="Queue for testing" style="color:#333" href="#" data-cmid="'+row.COMMS_MATRIX_ID+'" data-id="'+row.ID+'" data-src="'+row.SRC+'" data-dst="'+row.DST+'" data-protocol="'+row.PROTOCOL+'" data-ports="'+row.PORTS+'" data-spa="'+row.SPA+'" data-rpa="'+row.RPA+'" data-fpa="'+row.FPA+'"><i class="fa fa-cog" aria-hidden="true"></i></</button>';
}
html += '</div>';
return html;
},
},
{
"data": function(row,type,val,meta){
var dupes = '';
var content = '';
if(parseInt(row.DUPLICATES) > 0){
var cmids = row.CMIDS.split(", ");
for(var i=0;i<cmids.length;i++){
content += "<a href='"+window.location.protocol + "//" + window.location.host + "/api/user/commsmatrix/id/"+cmids[i]+"/format/xml" +"' target='_blank'>"+cmids[i]+"</a> ";
}
dupes = '<span data-toggle="popover" data-placement="top" data-title="duplicate flows" data-content="'+content+'" style="text-decoration:underline"><i class="fa fa-info-circle" aria-hidden="true"></i></span>';
}
if(routing_analysis){
var html = '<a target="_blank" href="/routing_analysis.php?src='+row.SRC+'&dst='+row.DST+'&proto='+row.PROTOCOL+'&port='+row.PORTS+'" data-toggle="popover" data-trigger="hover" data-content="Click to show routing analysis">'+row.ID+'</a>';
if(parseInt(row.DUPLICATES) > 0){
html += dupes;
}
return html;
}else{
if(parseInt(row.DUPLICATES) > 0){
return row.ID + dupes;
}
return row.ID;
}
}
},
{ "data": "CMLINE" },
{
"data": function(row,type,val,meta){
if(techops){
var html = '<div class="form-group">';
html += '<input type="checkbox" name="status[]" value="'+row.ID+'" class="form-control hidden-print">';
html += '<select id="'+row.ID+'_select" name="'+row.ID+'_select" class="status_option form-control">';
var selected = '';
for(i in statuses){
if(row.STATUS == statuses[i]){
selected = 'selected';
}
html += '<option value="'+statuses[i]+'" '+selected+'>'+statuses[i]+'</option>';
selected = '';
}
html += '</select></div>';
return html;
}else{
return row.STATUS;
}
}
},
{
"data": function(row,type,val,meta){
if(techops){
var inc = row.REMEDY_INC;
if(row.REMEDY_INC == null){
inc = '';
}
var html = '<input type="text" name="inc_'+row.ID+'" id="'+row.ID+'_inc" value="'+inc+'" maxlength="15" size="15" class="form-control" />';
return html;
}else{
return '';
}
}
},
{ "data": "SRC" },
{ "data": "SRC_DESC" },
{ "data": "SRC_ZONE" },
{ "data": "DST" },
{ "data": "DST_DESC" },
{ "data": "DST_ZONE" },
{ "data": "PROTOCOL" },
{ "data": "PORTS" },
{ "data": "NAT_DIR" },
{ "data": "NAT_IP" },
{ "data": "ENVIRONMENT" },
{ "data": "SERVICE_GROUPING" },
{ "data": "TRACK" },
{ "data": "REMARKS" },
{ "data": function(row,type,val,meta){
var html = '<span data-toggle="popover" data-trigger="hover" data-container="#dt-comms_matrix" data-content="<span style=\'color:black\'>'+row.SPN+'</span>">'+row.SPA+'</span>';
return html;
}
},
{ "data": "SPN" },
{ "data": function(row,type,val,meta){
var html = '<span data-toggle="popover" data-trigger="hover" data-container="#dt-comms_matrix" data-content="<span style=\'color:black\'>'+row.RPN+'</span>">'+row.RPA+'</span>';
return html;
}
},
{ "data": "RPN" },
{ "data": function(row,type,val,meta){
var html = '<span data-toggle="popover" data-trigger="hover" data-container="#dt-comms_matrix" data-content="<span style=\'color:black\'>'+row.FPN+'</span>">'+row.FPA+'</span>';
return html;
}
},
{ "data": "FPN" },
{
"data": function(row,type,val,meta){
var html = row.ECT;
if(row.ECT != 'None'){
html = ''+row.ECT+'';
}
return html;
}
},
],
});
} );
You will only be able to solve that with hardcoded CSS :
table#dt-comms_matrix thead tr:nth-child(2) th:nth-child(19) {
width: 400px;
min-width: 400px;
}
updated fiddle -> https://jsfiddle.net/aa9wnhd6/4/
table#dt-comms_matrix target the table
thead tr:nth-child(2) target the second header row
th:nth-child(19) target the 19th column
Alternatively set a class on the header element <th class="remarks"> and
table#dt-comms_matrix thead tr:nth-child(2) th.remarks { .. }
https://jsfiddle.net/aa9wnhd6/6/

I want to show my PDF in partial view where download option are not available its mandatory?

I want to show PDF without Download Option. After many search of Google I get some answer but I'm facing a problem in this.
PDF is open in partial View, but there have also Download Option. Is there another option to open Pdf without Download option?
#model Bizzop.Models.MyAccountModel
#{
Layout = null;
}
<html>
<head>
<title>INDEX</title>
</head>
<body>
<div id="divPartialView">
</div>
<div class="container">
#if (Model.MyAccountList.Count > 0)
{
foreach (var items in Model.MyAccountList)
{
<div class="video-row">
<a href="#" target="_blank" onclick="myPdf(this)"
id="#items.PdfName">
<div class="row">
#if (items.PdfName == "" || items.PdfName == null)
{
<img src="ImageName"/>
}
else
{
<img src="ImageName"/>
}
</div>
</a>
</div>
}
}
</div>
////// This is Ajax code where we pass File name when click the user in anchor
tag
<script>
function myPdf(e) {
debugger
var filen = e.id;
$.ajax({
url: "/MyAccount/MyPdfResult",
data: { pdfname: filen },
cache: false,
type: "POST",
dataType: "html",
type: "post",
success: function (data) {
SetData(data);
},
error: function (data) {
}
});
function SetData(data) {
$("#divPartialView").html(data); // HTML DOM replace
}
}
</script>
/////////// In Controller
public ActionResult MyPdfResult(string pdfname = null)
{
string embed = "<object data=\"{0}\" type=\"application/pdf\"
width=\"500px\" height=\"300px\">";
embed += "</object>";
TempData["Embed"] = string.Format(embed,
VirtualPathUtility.ToAbsolute("~/Content/TutorialImage/TutorialPdf/"+
pdfname));
return PartialView("_Viewpdf", TempData["Embed"]);
}
///// where i am create a Partial View
<div class="ancor">
#Html.Raw(TempData["Embed"])
</div>
i just tried it on my side and it worked for me. You need to make sure that your app is allowed to access the pdf file.
This is my code:
The controller:
[HttpPost]
[AllowAnonymous]
public ActionResult MyPdfResult(string pdfname = null)
{
string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"500px\" height=\"300px\">";
embed += "If you are unable to view file, you can download from here";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
TempData["Embed"] = string.Format(embed, VirtualPathUtility.ToAbsolute("~/Files/pdf.pdf"));
return PartialView("_Viewpdf", TempData["Embed"]);
}
The partial view:
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
#using (Html.BeginForm("MyPdfResult", "Home", FormMethod.Post))
{
View PDF
<hr />
#Html.Raw(TempData["Embed"])
}
The Index:
<div>
#Html.Partial("_Viewpdf");
</div>

Datatables .row() not working on reopening in bootstrap modal

I am creating the datatables in bootstrap modal and it is working fine for the first time modal opening, but when the modal is reopened, the datatable functions are not working.
$("#unitTypePopupModal .modal-body").empty();
var html = '<div class="container-fluid col-md-12">';
html += '<div class="row">';
html += '<div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">';
html += '<div class="panel panel-default">';
html += '<div class="panel-body">';
html += '<div class="text-center">';
html += '<img src="Images/add-circle.png" class="login" height="70" />';
html += '<h2 class="text-center">Units</h2>';
html += '<div class="panel-body">';
html += '<form id="unitTypePopupForm" name="unitTypePopupForm" role="form" class="form form-horizontal" method="post">';
//html += '<fieldset>';
html += '<div class="form-group">';
html += '<div id="table-container" style="padding:1%;">';
//if (UnitTypeData.length > 0) {
html += '<div class="table-responsive">';
html += '<table id="unitTypesList" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">';
html += '<thead>';
html += '<tr>';
html += '<th>' + '#' + '</th>';
html += '<th>' + 'UnitType Guid' + '</th>';
html += '<th>' + 'UnitType Name' + '</th>';
html += '<th>' + 'Unit List' + '</th>';
html += '<th>' + 'Operation' + '</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
for (var i = 0; i < UnitTypeData.length; i++) {
html += '<tr>';
html += '<td>' + '' + '</td>';
html += '<td>' + UnitTypeData[i].UnitTypeGuid + '</td>';
html += '<td>' + UnitTypeData[i].UnitTypeName + '</td>';
html += '<td>' + 'Unit' + '</td>';
html += '<td>' + '<i class="ui-tooltip fa fa-file-text-o" style="font-size: 22px;" data-original-title="View" title="View"></i>' + ' ' + '<i class="ui-tooltip fa fa-pencil-square-o" style="font-size: 22px;" data-original-title="Edit" title="Edit"></i>' + ' ' + '<i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete" title="Delete"></i>' + '</td>';
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
html += '</div>';
//} else {
// html += '<p>There is no Unit Type available to be displayed.</p>';
// }
html += '</div>';
html += '</div>';
//html += '</fieldset>';
html += '</form><!--/end form-->';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
$("#unitTypePopupModal .modal-body").append(html);
$('#unitTypePopupModal').modal('show');
$("#unitTypePopupModal").on('show.bs.modal', function () {
$("#unitTypePopupModal .modal-body").empty();
//bootbox.alert(html);
});
$("#unitTypePopupModal").on('hiddden.bs.modal', function () {
//$("#unitTypePopupModal .modal-body").empty();
$(this).data('bs.modal', null);
});
unitTypeTableRelatedFunctions();
$('#unitTypePopupForm').validate({ // initialize plugin
ignore: ":not(:visible)",
rules: {
unitTypeName: {
required: true,
noSpace: true
}
},
messages: {
unitTypeName: {
required: "Please Enter the UnitType Name.",
noSpace: "UnitType Name cannot be empty."
}
},
//errorPlacement: function (error, element) {
// switch (element.attr("name")) {
// case "dpProgressMonth":
// error.insertAfter($("#dpProgressMonth"));
// break;
// default:
// //nothing
// }
//}
});
The following function is called
unitTypeTableRelatedFunctions = function () {
var unitTypeEditing = null;
var table = $('#unitTypesList').DataTable({
responsive: true,
pagingType: "full_numbers",
searchHighlight: true,
stateSave: true,
destroy: true,
//orderable: false,
columnDefs: [
{
targets: [0],
orderable: false,
searchable: false
},
{
className: 'never',//className:'hidden',
targets: [1],
visible: false,
orderable: false,
searchable: false
},
{
targets: [2],
orderable: true
},
{
targets: [3],
orderable: false
},
{
targets: [4],
orderable: false,
searchable: false,
//defaultContent: '<a class="viewWorkItemSubHeadBtn" onclick="editBtnClicked(this);"><i class="ui-tooltip fa fa-file-text-o" style="font-size: 22px;" data-original-title="View"></i></a> <a class="editWorkItemSubHeadBtn"><i class="ui-tooltip fa fa-pencil" style="font-size: 22px;" data-original-title="Edit"></i></a> <a class="deleteWorkItemSubHeadBtn"><i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete"></i></a>'
}
],
order: [[2, 'desc']],
language: {
//"lengthMenu": "Display _MENU_ records per page",
lengthMenu: 'Display <select>' +
'<option value="5">5</option>' +
'<option value="10">10</option>' +
'<option value="15">15</option>' +
'<option value="20">20</option>' +
'<option value="25">25</option>' +
'<option value="30">30</option>' +
'<option value="35">35</option>' +
'<option value="40">40</option>' +
'<option value="45">45</option>' +
'<option value="50">50</option>' +
'<option value="100">100</option>' +
'<option value="-1">All</option>' +
'</select> records per page',
zeroRecords: "Nothing found - sorry",
info: "Showing page _PAGE_ of _PAGES_",
infoEmpty: "No records available",
infoFiltered: "(filtered from _MAX_ total records)"
},
pageLength: 5,
//select: {
// style: 'os',
// blurable: true
//},
dom: '<"top"<"pull-left"B><f>>rt<"bottom"i<"pull-left"l><p>><"clear">',
//dom: '<lf<t>ip>',
//dom: '<"wrapper"flipt>',
//dom: '<"top"i>rt<"bottom"flp><"clear">',
buttons: [
{
text: '+ Create New UnitType',
className: 'btn-success addNewUnitTypeBtn',
action: function (e, dt, node, config) {
e.preventDefault();
addNewUnitType();
}
}
]
});
table.on('order.dt search.dt', function () {
table.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
$('#unitTypePopupModal').on('click', '#unitTypesList a.editUnitTypeBtn', function (e) {
e.preventDefault();
/* Get the row as a parent of the link that was clicked on */
var selectedRow = $(this).parents('tr')[0];
//var selectedRowIndex = table.row($(this).parents('tr')).index();
if (unitTypeEditing !== null && unitTypeEditing != selectedRow) {
/* A different row is being edited - the edit should be cancelled and this row edited */
restoreUnitTypeRowData(table, unitTypeEditing);
editUnitTypeRow(table, selectedRow);
unitTypeEditing = selectedRow;
addUnitTypeBtn.enable();
$('#unitTypePopupModal input#unitTypeName').focus();
}
//else if (nEditing == selectedRow && this.innerHTML == "Save") {
// /* This row is being edited and should be saved */
// saveRow(oTable, nEditing);
// nEditing = null;
// createBtnClicked = 0;
//}
else {
/* No row currently being edited */
editUnitTypeRow(table, selectedRow);
unitTypeEditing = selectedRow;
addUnitTypeBtn.enable();
$('#unitTypePopupModal input#unitTypeName').focus();
}
});
When edit button is clicked, the click event is fired and the following function is called:
editUnitTypeRow(table, selectedRow)
the function body is:
editUnitTypeRow = function (table, selectedRow) {
var selectedRowData = table.row(selectedRow).data();
var availableTds = $('>td', selectedRow);
availableTds[1].innerHTML = '<input type="text" id="unitTypeName" name="unitTypeName" placeholder="UnitType Name" class="form-control text-capitalize" value="' + selectedRowData[2] + '">';//UnitType
availableTds[2].innerHTML = '';
availableTds[3].innerHTML = '<i class="ui-tooltip fa fa-floppy-o" style="font-size: 22px;" data-original-title="Save" title="Save"></i>' + ' ' + '<i class="ui-tooltip fa fa-times-circle-o" style="font-size: 22px;" data-original-title="Cancel" title="Cancel"></i>'
}
In this function the table row data is not extracted properly.
I am getting the data when the modal is opened for the first time after page reload but if i open the modal second time the table.row() function is not fetching the row data, but the data is present in the row.
The html code is as follows:
<div id="unitTypePopupModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" style="overflow-y:initial !important;">
<div class="modal-content">
<div class="modal-header" style="display:none"></div>
<%--<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 class="text-center">What's My Password?</h1>
</div>--%>
<div class="modal-body" style="max-height:calc(100vh - 200px); overflow-y: auto;">
</div>
<div class="modal-footer">
<div class="col-md-12">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
</div>
</div>
The clicks in popup modal works initially after page load but do not work after we re-open the popup modal.
Since you are dinamically adding html content, you need to delegate events in a different way
Code like this will execute only if object #selector is present on page at load time
$('#selector').on('click', function(){...etc...});
If you want to delegate event to dinamically added elements, you have to do like this:
$('#container').on('click', '#selector', function(){...etc...});
Where #container exist in DOM since page load. If you want to be 100% sure not to do mistake, just use $(document.body).on(...), but it will slow down a bit your code since the body is full of elements
EDIT after fiddle #12: I'm sorry but your code is way too crowded to easily find a solution. I tried to log some data and I see that when you close and reopen the modal, the event is triggered twice both when you click "Edit" and "Cancel" (I guess other buttons behave the same), so it is actually working correctly, but the secont time it is called, the unitTypeEditing is empty, that's why the input field isn't hiding..
I suggest you to switch to x-editable plugin, this should avoid any problem with restoring previous data and it will result in much less code to write.

Dojo TabContainer doesn't get formatted correctly until after I do an Inspect Element

I have a Dojo DataGrid with a few rows of data. When I click on a row, I have a TabContainer created in another <div>. Here's what it ends up looking like:
The formatting for the TabContainer is incorrect. However, after I do an "Inspect Element", the formatting corrects itself:
However, the Submit button disappears after the formatting is corrected.
Here's the code I use to create the DataGrid and TabContainer:
<div id="r_body">
<div id="r_list">
</div>
<div id="r_form">
<div data-dojo-type="dijit/form/Form" id="parameters_form" data-dojo-id="parameters_form" encType="multipart/form-data" action="" method="">
{% csrf_token %}
<div>
<div id="r_tab_container"></div>
</div>
<div>
<p></p>
<button id="submit_parameters" dojoType="dijit/form/Button" type="submit" name="submitButton" value="Submit">
Submit
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
require([
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojox/grid/DataGrid" ,
"dojo/data/ItemFileWriteStore" ,
"dojo/dom",
"dojo/domReady!"
], function(BorderContainer, ContentPane, DataGrid, ItemFileWriteStore, dom){
// create a BorderContainer as the top widget in the hierarchy
var bc = new BorderContainer({
style: "height: 500px; width: 230px;"
}, "r_list");
/*set up data store*/
var data = {
identifier: "id",
items: []
};
data.items.push({ id: 'some_id', description: 'some_description',
var store = new ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Title', 'field': 'description', 'width': '200px', 'noresize': true}
]];
/*create a new grid*/
var r_list_grid = new DataGrid({
region: "left",
id: 'r_list_grid',
store: store,
structure: layout,
rowSelector: '0px'
});
bc.addChild(rt_list_grid);
bc.startup();
list_grid.on("RowClick", gridRowClick);
function gridRowClick(evt){
var idx = evt.rowIndex;
var rowData = list_grid.getItem(idx);
var r_url = rowData['url'][0];
var r_id = rowData['id'][0]
require(["dojo/dom", "dojo/request/xhr", "dojo/dom-form", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/ready", "dojo/domReady!"],
function(dom, xhr, domForm, TabContainer, ContentPane, ready){
var url = window.location.pathname + "dev/" + r_id + "/" + r_url + "/";
xhr(url, {
method: "get"
}).then(
function(response){
var json_response = JSON.parse(response);
var fields_dict = json_response['fields_dict'];
var tc = new TabContainer({
style: "height: 100%; width: 100%;"
}, "r_tab_container");
for(var key in fields_dict) {
var content_string = '';
var fields = fields_dict[key];
for(var field in fields) content_string += '<div>' + field + '</div>';
var tcp = new ContentPane({
title: key,
content: content_string
});
tc.addChild(tcp);
}
tc.startup();
},
function(error){
//Error stuff
}
);
});
}
});
</script>
So what's going here and how do I fix the TabContainer formatting? Thanks!
I had to do a tc.resize(); after I do the tc.startup();