Bootstrap 3 - Popover in wrong position the first time page loads - twitter-bootstrap-3

Bootstrap 3 popper's container is not correctly placed on the page the first time the user 'hovers' over the element triggering it. the second time onward, works like a charm.
HTML:
<table>
<thead>
<th>1</th>
<th>2</th>
<th>3</th>
</thead
<tbody>
<tr>
<td>AAA</td>
<td>BBB</td>
<td>CCC</td>
</tr>
<tr>
<td>AAA</td>
<td>BBB</td>
<td>
<span class="glyphicon glyphicon-cog popover-me"></span>
</td>
</tr>
<tr>
<td>AAA</td>
<td>BBB</td>
<td>CCC</td>
</tr>
<tr>
<td>AAA</td>
<td>BBB</td>
<td>CCC</td>
</tr>
</tbody>
</table>
JS:
$('.popover-me').popover({
html: true,
trigger: 'hover',
placement: 'auto right',
container: 'body',
title: 'Title',
content: function(){
return '<img src="http://via.placeholder.com/150x150"/>';
}
});
JSFiddle: https://jsfiddle.net/wp083g18/2/
(you need to refresh if you want to see it again)

I think the problem is due to image loading, so the popover content is resized after showing.
So I suggest to add CSS to fix size of popover content:
.popover-content {
min-width: 150px;
min-height: 150px;
}
and/or preload image:
var img_url = "https://via.placeholder.com/150x150";
function preloadImage(url) {
console.log("preloadImage: "+url);
var img = new Image();
img.src = url;
}
preloadImage(img_url);
Check this fiddle: https://jsfiddle.net/beaver71/sysz405s/
Another option is dynamic placement of popover:
placement: function(pop, ele) {
if ($(ele).parent().is('td:last-child')) {
return 'left';
}
return 'right';
},

Related

How to style a table in a vue.js component

I am trying to style the table in this vue component, my understanding is that I need to create the css from the data function and then bind it to the appropriate element in the template.
What I am trying to do is apply the following css to my table
css:
.table-striped>tr:nth-of-type(odd) {
background-color: #f9f9f9
}
vue component:
Vue.component('overview', {
delimiters: [ '[[', ']]' ],
props: ['job_execs'],
template: `
<div overview>
<h3>Overview</h3>
<table class="table table-striped table-bordered">
<tr>
<td>Start Time</td>
<td>[[ job_execs[0].time_start ]]</td>
</tr>
<tr>
<td>End Time</td>
<td>[[ job_execs[0].time_end ]]</td>
</tr>
<tr>
<td>Job</td>
<td>http://placeholder</td>
</tr>
</table>
</div>
`,
data: function() {
return {
divExample: {
color: 'red',
fontSize: '13px'
}
}
},
});
Im not sure how to 1. create this CSS from the data function and 2. Bind it within the template.
I am currently working on a project where I need to take an existing web app and convert the front end to vue.js and it seems like its going to be a real headache extracting the css I need from the already bloated css that exists and then converting it to vue js functions that inject that css per component.
You can bind css properties to a tag in Vue using the following way:
<tr>
<td>Start Time</td>
<td>[[ job_execs[0].time_start ]]</td>
</tr>
<tr v-bind:style="strippedTr">
<td>End Time</td>
<td>[[ job_execs[0].time_end ]]</td>
</tr>
<tr>
<td>Job</td>
<td>http://placeholder</td>
</tr>
...
data: function() {
return {
strippedTr: {
'background-color': '#f9f9f9'
}
}
},

Add active class a column to table (as in netflix)

I need help to select a table header and select your column using classes. As in Netflix. I'm noob in VueJS
Example GIF
My code is
<table class="table">
<thead class="text-center">
<tr>
<th scope="col"><button type="button" class="btn plan_columnA selected" #click="planSelect('plan_columnA')">Column A</button></th>
<th scope="col"><button type="button" class="btn plan_columnB" #click="planSelect('plan_columnB')">Column B</button></th>
<th scope="col"><button type="button" class="btn plan_columnC" #click="planSelect('plan_columnC')">Column C</button></th>
</tr>
</thead>
<tbody class="text-center">
<tr>
<td class="plan_columnA selected">Mark</td>
<td class="plan_columnB">Otto</td>
<td class="plan_columnC">#mdo</td>
</tr>
<tr>
<td class="plan_columnA selected">Jacob</td>
<td class="plan_columnB">Thornton</td>
<td class="plan_columnC">#fat</td>
</tr>
<tr>
<td class="plan_columnA selected">Larry</td>
<td class="plan_columnB">the Bird</td>
<td class="plan_columnC">#twitter</td>
</tr>
</tbody>
</table>
My style is
.btn {
background-color: darkgrey;
color: white;
}
button.selected {
background-color: red;
}
td.selected {
color: red;
}
I try to do this, but I do not know if it's right
export default {
data () {
return {
planSelected: '',
}
},
methods: {
planSelect (plan) {
this.planSelected = plan;
$('.selected').removeClass('selected');
$('.' + this.planSelected).addClass('selected');
},
},
}
I tried JQuery, but I want to do it in VueJS.
Thanks!
That's fairly easy, i've made an example for you in a fiddle, hope it helps you on the way. It should be made more dynamically, for better overview, but you can play around with the code i've made.
In the perfect scenario, you would generate all rows/columns from a data variable, instead of doing all this manually.
https://jsfiddle.net/6aojqm0k/
What i've made is just having 1 data variable, which you set and check for on the different tds and buttons.
data: () => ({
planSelected: 'plan_columnA'
})
Button to choose the plan:
<button type="button" class="btn plan_columnA" :class="{selected: planSelected === 'plan_columnA' }" #click="planSelected = 'plan_columnA'">Column A</button>
And the actual column to show selected
<td class="plan_columnA" :class="{selected: planSelected === 'plan_columnA' }">Mark</td>
Pro tip: Never combine jQuery and VueJS - Just use VueJS

Datatables buttons pdfHtml5 exportOptions to remove nested tags

I'm trying to optimize the Datatables buttons pdfHtml5 export of a page. The table data contains nested html tags which are creating additional space above and below the cell data, which makes the PDF very long.
The text in my cell is wrapped in two nested <div> and a <p>. In the PDF export, I only need the contents of the <p>
<td>
<div class="flagimg" style="background-image: url(...)">
<div class="flagtext">
<p>name of country</p>
</div>
</div>
</td>
I'm trying to remove nested html tags using exportOptions, but I'm not sure how to write the syntax correctly. Can anyone help me with this?
$(document).ready(function() {
var buttonCommon = {
exportOptions: {
format: {
body: function(data, column, row) {
data = data.replace(/<div class="flagtext"\">/, '');
data = data.replace(/<.*?>/g, "");
return data;
}
}
}
};
var oTable = $('#example').DataTable({
dom: 'Bfrtip',
buttons: [
$.extend( true, {}, buttonCommon, {
extend: 'copyHtml5'
} ),
$.extend( true, {}, buttonCommon, {
extend: 'excelHtml5'
} ),
$.extend( true, {}, buttonCommon, {
extend: 'pdfHtml5'
} )
]
});
})
I finally discovered that the problem is not the nested div after all, but rather that the tags are indented in the code instead of being on one line. I've reported this to Datatables and I'm documenting the problem here, in case anyone else runs into it.
I've built on the fiddle #davidkonrad made to illustrate what's happening.
https://jsfiddle.net/lbriquet/7f08n0qa/
In the first row, the nested tags are indented in the code... this produces extra space above and below the country name data in the PDF export.
In the second row I've put all of the tags in the same line of code... and no extra spacing is produced in the PDF export.
<table id="example" width="100%" border="0" cellspacing="0" cellpadding="0" >
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="myclass">Company name
</div>
</td>
<td>
<div class="flagimg" style="background-image: url(#">
<div class="flagtext">
<p>Country name</p>
</div>
</div>
</td>
<td>
<div class="myclass">Product sold</div>
</td>
</tr>
<tr>
<td>
<div class="myclass">Company name
</div>
</td>
<td><div class="flagimg" style="background-image: url(#)"><div class="flagtext"><p>Country name</p></div></div>
</td>
<td>
<div class="myclass">Product sold</div>
</td>
</tr>
</tbody>
</table>

dijit.Dialog.hide() exception in animation handler for: onEnd

I am creating a dijit Dialog and then hiding it with a OK/Cancel button. As the dialog hides, I always get the follow errors in the javascript console:
exception in animation handler for: onEnd
TypeError: Cannot read property 'remove' of undefined(…)
See here: https://www.youtube.com/watch?v=QcEUsllrRGs
The error doesn't seem to affect anything, but I'd sure love to resolve it so I don't confuse that error for a real functional issue while debugging.
I've read many suggestions regarding similar errors... using lang.hitch, disconnecting from events, but nothing seems to work/be applicable. Help?!
Here's a snippet of my Dialog code:
function showMessageDialog(title, message, width) {
var content,
focusOnOkButton = function () {
dojo.byId('messageDialogOk').focus();
};
if (!dijit.byId("messageDialog")) {
new dijit.Dialog({}, "messageDialog").startup();
new dijit.form.Button({
onClick: function() {
dijit.byId('messageDialog').hide();
}
}, "messageDialogOk").startup();
}
if (width) {
dojo.byId('messageDialogTable').style.width = width + "px";
} else {
dojo.byId('messageDialogTable').style.width = "450px";
}
dijit.byId('messageDialog').resize();
dijit.byId('messageDialog').set("title", title);
content = dojo.byId("messageDialogMessage");
dojo.empty(content);
content.innerHTML = message;
dijit.byId('messageDialog').show();
setTimeout(focusOnOkButton, 50);
}
....and the associated HTML:
<div id="messageDialog" style="display:none;">
<table id="messageDialogTable" style="width:450px;table-layout: fixed;">
<tr>
<td colspan="2" style="padding: 0 0px 0px 5px;">
<table style="width: 100%;">
<tr>
<td id="messageDialogMessage" style="font-size: 10pt;"></td>
</tr>
<tr>
<td style="padding: 5px;text-align: center;">
<div id="messageDialogOk">OK</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
I tried to duplicate the problem with a simple JSFiddle example, but could not... so there's something going in in my app... but not sure what it could be.

Editing subrow - jquery easyui edatagrid

OK- I have been beating my head against this since last Friday, I figure it is finally time to post for help. I think I have my code fairly settled, and I think things should work.
I have a grid where I edit the row, add rows, and then I expand the rows loading a subgrid (editable edatagrid). I want to simply edit and cancel the editable subgrid. However also want to take the ID column that I pass to the server page for updating from the parent row (api).
Editing and adding new rows is working, opening the fields I want as editable in an editable grid in the sub row is working. However getting the sub grid to cancel edit, save, and use iconCls will not work (iconCls code removed at the moment for the subgrid). I have not included all the code, just what is relevant to the question here so there are some other calls with missing javascript. If anybody would like that code just holler, and I will include it.
master grid
<section class="grid">
<table id="wells" class="easyui-datagrid" title=" " style="width:100%;height:500px"
pagination="true" idField="api" fitColumns="true" url="getinfo.php"
collapsible="true" singleSelect="true" toolbar="#tb" resizeHandle="both"
autoRowHeight="true" nowrap="false" rownumbers="true" pageList="[10,25,50,100,5000]">
<thead>
<tr>
<th data-options="field:'well_name', width:48" sortable="true">Name</th>
<th data-options="field:'well_num',width:18" sortable="true">Num</th>
<th data-options="field:'field',width:48" sortable="true">Field</th>
<th data-options="field:'pad',width:36" sortable="true">Pad</th>
<th data-options="field:'api',width:32" sortable="true">API</th>
<th data-options="field:'legal_description',width:46" sortable="true">Legal</th>
<th data-options="field:'county_state',width:40" sortable="true">County, State</th>
<th data-options="field:'lease',width:33" sortable="true">Lease</th>
<th data-options="field:'unit_ca_pa',width:57" sortable="true">Unit CA PA</th>
<th data-options="field:'status',width:27">Status</th>
<th data-options="field:'status_date',width:22">Updated</th>
<th data-options="field:'wildlife_stips',width:75">Wildlife Stips</th>
<th data-options="field:'notes',width:75">Notes</th>
</tr>
</thead>
</table>
master grid toolbar
<div id="tb" style="padding:3px"><span>Field:</span>
<input id="field" style="line-height:22px;border:1px solid #ccc">
<span>Pad:</span>
<input id="pad" style="line-height:22px;border:1px solid #ccc">
<span>API:</span>
<input id="api" style="line-height:22px;border:1px solid #ccc">
Search
Reset
New Well
Edit Well
</div>
expandable, edatagrid section
<script type="text/javascript">
$('#wells').datagrid(
{
view: detailview,
detailFormatter:function(index,row)
{ return '<div style="padding:2px"><table class="ddv"></table></div>'; },
onExpandRow: function(index,row)
{
var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
ddv.edatagrid(
{
url:'geteditexpand.php?api='+row.api,
saveUrl:'updateeditwell.php?api='+row.api,
fitColumns:true,
singleSelect:true,
rownumbers:true,
loadMsg:'',
height:'auto',
columns:[[
{field:'location',title:'Location'},
{field:'NorthSouth',title:'N+S-',editor:'text'},
{field:'EastWest',title:'E+W-',editor:'text'},
{field:'latitude',title:'Latitude',editor:'text'},
{field:'longitude',title:'Longitude',editor:'text'},
{field:'lot',title:'Lot',editor:'text'},
{field:'tract',title:'Tract',editor:'text'},
{field: 'action', title: 'Action',
formatter:function(value,row,index)
{
var s = 'Save ';
var c = 'Cancel';
return s+c;
}
}
]],
onResize:function()
{ $('#wells').edatagrid('fixDetailRowHeight',index); },
onLoadSuccess:function()
{
setTimeout(function(){
$('#wells').edatagrid('fixDetailRowHeight',index);
},0);
}
});
$('#wells').datagrid('fixDetailRowHeight',index);
}
});
</script>
you dont have updateURL, im not sure
url(source)
saveUrl(NewRecord)
missing
updateUrl:'updatefile.php'