jQuery accordian in Vue js component - vue.js

I have a child component in Vue js. Where i have a list of object which i am filtering based on InvGroup. I am facing issue when trying to create accordion format. I tried using , tag to surround the accordion content but none of them work. Please suggest a solution.
<div id="accordion" class="div-shadow col-md-12 col-lg-12 col-sm-12 col-xs-12">
<div v-for="invGroup in invGroupTotals">
<label>{{invGroup.Group}}<span style="float:right;" v-if="invGroup.DiffTotal === 0" class="text-success"> No Difference </span><span class="text-danger" style="float:right;" v-else>Diffrence Count {{invGroup.DiffTotal}} , Amount ${{invGroup.DiffAmtTotal}}</span></label>
<div style="text-align: center; background-color: white;height:400px;overflow-y:scroll;" >
<table cellpadding="10" style="border-style: solid; border-color: Gray; border-collapse: separate;border-spacing: 2px" class="table tableStyle col-md-12 col-lg-12 col-sm-12 col-xs-12">
<tr>
<th v-for="column in weeklyReconcileGridColumns">{{column}}</th>
</tr>
<template v-for="item in weeklyReconcileList">
<tr v-if="invGroup.Group === item.UPCGroup">
<td >{{item.UPCID}}</td>
<td class="text-left" v-on:click="showItemHistory(item.UPCID, item.UPCDesc)">{{item.UPCDesc}}</td>
<td >{{item.SystemBOH}}</td>
<td >{{item.CurrentWeekBOH}}</td>
<td >{{item.Diffrence}}</td>
<td >{{item.TotalSalesAmount}}</td>
</tr>
</div>
<tr>
<td class="text-center" colspan="2"> Total</td>
<td> {{invGroup.SysTotal}}</td>
<td> {{invGroup.CountedTotal}}</td>
<td> {{invGroup.DiffTotal}}</td>
<td> {{invGroup.DiffAmtTotal}}</td>
</tr
</table>
</div>
I added the jquery in updated method.
updated: function () {
$("#accordion").accordion();
}
The problem is the looping tag should not be surrounded by and HTML tag.

Try using template tag instead of div tag

Related

How to ignore that clicking on a TD tag does not automatically redirect me to another view? Vue

I have a table where in each TR when I click it redirects me to another view with the detail, the idea is that I have never worked with Vue and I can't think how to disable the event when I click on the first TD tag of the table.
Before in Jquery I did it this way:
//Add onclick to TR
$('table tr').click(function(e) {
// Avoid redirecting if it's a delete button
if(!$(e.currentTarget).hasClass('delete')) {
// Not a button, redirect by taking the attribute from data-route
window.location.href = $(e.currentTarget).data('route');
}
});
But with Vue I don't know how to do it in the onclick event.
This is my table and the method
<table
id="accounts-table"
class="
table table-listbox
table-bordered_
table-responsive-md
table-striped_
text-center_
"
>
<thead>
</thead>
<tbody>
<tr v-if="tableData.length === 0">
<td colspan="4" class="text-center">
No hay oportunidades para mostrar.
</td>
</tr>
<template v-if="loading === true">
<tr colspan="9" class="text-center">
<b-spinner variant="primary" label="Spinning"></b-spinner>
<b-spinner variant="primary" type="grow" label="Spinning"></b-spinner>
</tr>
</template>
<template v-else>
<tr
v-for="(data, k) in tableData"
:key="k"
#click="viewOpportunity(k, data)"
>
<slot :row="data">
<td v-if="permissions.includes('view all opportunities')" width="10">
<div class="iq-email-sender-info">
<div class="iq-checkbox-mail">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="mailk">
<label class="custom-control-label" for="mailk"></label>
</div>
</div>
</div>
</td>
<td width="20">
<vue-avatar
:username="data.sales_man"
:title="data.sales_man"
:size="32"
v-if="data.sales_man != ''"
></vue-avatar>
</td>
<td width="5">
<template v-if="data.has_file != false">
<i
class="ri-attachment-line"
style="font-size: 20px; color: #007bff"
></i>
</template>
</td>
<td width="120" nowrap>
<template>
<p class="mb-0">{{ data.created_at }}</p>
<small class="text-info mt-5">
Fecha creación
</small>
</template>
</td>
</slot>
</tr>
</template>
</tbody>
</table>
viewOpportunity(data) {
window.location.href = "/opportunity/" + data.id;
},
For example in the first TD of the table I would like that it does not redirect me to the page but from the 2nd TD it redirects me.
On first td element use this even modifier - #click.stop
Prevent on click on parent when clicking button inside div
This kind of issue ever answered .. please have a look on this
If someone needs an href inside a table that has a that has a #click method in the row, but you wat to the link does not fire the click event in the row and also to prevent event propagation when there is no method to call, e.g. a simple <a href="mailto:someone#example.org"> link, try to use this trick with #click.self:
BEFORE
<table>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>
<tr #click="myMethodFromRow">
<td>Some Value</td>
<td>
<a target="_blank" :href="mailto:someone#example.org"> My link </a>
</td>
</tr>
</table>
AFTER
<table>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>
<tr>
<td #click="myMethodFromRow">Some Value</td>
<td #click.self="myMethodFromRow">
<a target="_blank" :href="mailto:someone#example.org"> My link </a>
</td>
</tr>
</table>
In this case I wanted to execute myMethodFromRow clicking inside each td, but not clicking the link. So I changed the myMethodFromRow method from the tr and put it into each td. But the most important trik was to use #click.self for the td with the href link.
.self only trigger handler if event.target is the element itself, i.e. not from a child element.
DOCUMENTATION: https://vuejs.org/guide/essentials/event-handling.html#event-modifiers

Selenium XPath for bold <b></b> tag

Below is the HTML containing the b (bold) tags i want to get the XPath for.
<tbody>
<tr>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">..</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>Xyz</B></DIV>">
<b>Xyz</b>
</div>
</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>01/01/2019</B></DIV>">
<b>01/01/2019</b>
</div>
</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">..</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>Abc</B></DIV>">
<b>Abc</b>
</div>
</td>
</tr>
</tbody>
I came up with this xpath: //div[#class='get-HTML']/b but there are many other b tags.
For example if I had to read the text at the below tag, how do I be precise?
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner="<DIV class=gwt-HTML><B>01/01/2019</B></DIV>">
<b>01/01/2019</b>
</div>`
Tried this xpath but it didnt work:
//div[#class='get-HTML']/b[2]
Can you please help me crack this xpath?
Because the HTML tree is identical above all b elements -- meaning, tr/td/div/b will always retrieve 3 different b elements, you will need to use an index to access the desired element.
Depending on the b tag you want to retrieve, you will need to use the index of td elements to get the tag, because there are multiple td elements on the same level:
//tr/td[index]/div/b
Applying this example, we can retrieve b tags as such:
To get Xyz: //tr/td[2]/div/b
To get 01/01/2019: //tr/td[3]/div/b
To get abc: //tr/td[5]/div/b
Alternatively, if you would like to get the b tag based on its text, the path is different:
//b[text()='xyz']
However, this will only get you one b element, and you must know its text beforehand, so this approach is not desirable if you do not know the text inside the b elements.
If you want to be really specific include more parent elements in your XPath.
Easy trick to always get the correct XPath: Use Google Chrome Inspector > Select element > Right click HTML tag > Copy > XPath
In this case:
<tbody>
<tr>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">..</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>Xyz</B></DIV>">
<b>Xyz</b>
</div>
</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>01/01/2019</B></DIV>">
<b>01/01/2019</b>
</div>
</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">..</td>
<td align="left" style="VERTICAL-ALIGN: top" rowSpan="1" colSpan="1">
<div class="get-HTML" __listner=" <DIV class=gwt-HTML><B>Abc</B></DIV>">
<b>Abc</b>
</div>
</td>
</tr>
</tbody>
The XPath for the third b tag is: /html/body/div[3]/b
In your case, maybe you need to remove the /html/body/ maybe not. It depends on what parent elements your HTML code is in.
Note: so the XPath changes when you use different parent elements if you use this precise method. eg: It can be more difficult to implement on dynamically generated pages.

dynamic jquery accordion not working in vue.js

I have requirement when I am creating accordion dynamically. I have a list using which, i will filter the record and create accordion based on selected date. Below is the code for accordion
<div id="accordion" class="accordion" style="margin-top:20px;" class="div-shadow col-md-12 col-lg-12 col-sm-12 col-xs-12">
<template v-for="invGroup in invGroupTotals">
<label>{{invGroup.Group}}<span style="float:right; font-size:12px" v-if="invGroup.DiffTotal === 0 && invGroup.DiffAmtTotal === zero" class="text-success"> No Difference </span><span class="text-danger" style="float:right; font-size:12px" v-else>Difference Count {{invGroup.DiffTotal}} , Amount ${{invGroup.DiffAmtTotal}}</span></label>
<div style="text-align: center; background-color: white; overflow-y:auto;" >
<table cellpadding="10" style="border-style: solid; border-color: Gray; border-collapse: separate;border-spacing: 2px" class="table tableStyle col-md-12 col-lg-12 col-sm-12 col-xs-12">
<tr>
<th v-for="column in weeklyReconcileGridColumns">{{column}}</th>
</tr>
<template v-for="item in weeklyReconcileList">
<tr v-if="invGroup.Group === item.UPCGroup">
<td >{{item.UPCID}}</td>
<td class="text-left" v-on:click="showItemHistory(item.UPCID, item.UPCDesc)">{{item.UPCDesc}}</td>
<td >{{item.SystemBOH}}</td>
<td >{{item.CurrentWeekBOH}}</td>
<td >{{item.Diffrence}}</td>
<td >{{parseFloat(item.TotalSalesAmount).toFixed(2)}}</td>
</tr>
</template>
<tr>
<td class="text-center" colspan="2"> Total</td>
<td> {{invGroup.SysTotal}}</td>
<td> {{invGroup.CountedTotal}}</td>
<td> {{invGroup.DiffTotal}}</td>
<td> {{invGroup.DiffAmtTotal}}</td>
</tr>
</table>
</div>
The problem is, suppose on the first load 2 accordion is shown. When changed the date there are three accordion then the accordion style is not applied in third one. I am calling the accordion in Updated Hook as shown below.
updated: function () {
$("#accordion").accordion();}
Could you please suggest how can i correct the issue. thanks in advance.
I made it working by refreshing the accordion. The only thing we need to take care is refreshing after accordion is instantiated. check other methods click here.

XPath: Get previous item, filtering by class

I have this HTML:
<div class="DivHeaderSizes" data-subgroup="1">
<img style="display:none" class="help-size-img-colorbox" data-subgroup="1_Man" src="Man.gif">
<div class="subgroup-description">Jogging</div>
<div class="help-size-link cboxElement" data-subgroup="1_Man">Tutorial</div>
</div>
<div style="float: left;" class="DivSizeElement">
<table data-size="41" class="SizeElement" style="display: none;">
<tbody>
<tr>
<td class="td-label-size">
<span class="label-size" data-size="41">41</span>
</td>
<td class="td-label-textbox">
<input name="ctl00$CthBody$sizelist$TxtSize_41" type="text" maxlength="4" id="CthBody_sizelist_TxtSize_41" class="txt-Size" data-price="19.50" data-size="41" data-available="0" data-subgroup="1" style="width:30px;">
</td>
</tr>
</tbody>
</table>
</div>
<div style="float: left;" class="DivSizeElement">
<table data-size="42" class="SizeElement" style="display: none;">
<tbody>
<tr>
<td class="td-label-size">
<span class="label-size" data-size="42">42</span>
</td>
<td class="td-label-textbox">
<input name="ctl00$CthBody$sizelist$TxtSize_S" type="text" maxlength="4" id="CthBody_sizelist_TxtSize_S" class="txt-Size" data-price="19.50" data-size="42" data-available="0" data-subgroup="1" style="width:30px;">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Using Selenium with C# and starting from input element with name
ctl00$CthBody$sizelist$TxtSize_41
I want the XPath expression to get the text "Jogging". Thanks.
If the context node is input[#name='ctl00$CthBody$sizelist$TxtSize_41'], then the following XPath will select the div containing "Jogging":
(preceding::div[#class='subgroup-description'])[1]
Or you could use:
ancestor::div[1]/preceding-sibling::div[1]/div[#class='subgroup-description']

How can i achieve truncated text in a responsive width table column?

I have a table with 4 columns. The second column displays an email address and i'd like that column to take up the maximum amount of width within the table that it can. Then when the viewport size becomes smaller, the column width should be responsive and the email displayed should truncate if it becomes too large for the column.
All the solutions i've found so far either use table: {table-layout:fixed;} or set a max-width value on the td. Which are no good for me as they force the columns to specific widths.
This is what i'm trying to achieve regarding the column width layout, but the truncation fails. I read on an SO comment (showing the max-width solution) that setting width: 100% and min-width: 1px would have the desired affect, but it doesn't appear to work.
http://plnkr.co/edit/gIC5u6wq6oCYhF5pCJJp?p=preview
This is a max-width example where at least the text truncates, but the column widths are wrong.
http://plnkr.co/edit/e8sj2iqRUpBytMomddCS?p=preview
I've also tried wrapping the email text in a div, setting the width of the td to 100% and then setting the truncation on the inner div (also with width: inherit) but that didn't work either.
Add a class to other columns i.e Checkbox, Staff and Client columns and fix their width by giving appropriate widths.
Below is the HTML and CSS code:
HTML
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery#*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script data-require="bootstrap#3.1.1" data-semver="3.1.1" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link data-require="bootstrap-css#3.1.1" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
<body>
<div class="container">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>Email</th>
<th class="text-center">Staff</th>
<th class="text-center">Client</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center other-col">
<input type="checkbox">
</td>
<td class="email-col">
example#example.com
</td>
<td class="text-center other-col">
yes
</td>
<td class="text-center other-col">
no
</td>
</tr>
<tr>
<td class="text-center other-col">
<input type="checkbox">
</td>
<td class="email-col">
example#example.com
</td>
<td class="text-center other-col">
yes
</td>
<td class="text-center other-col">
no
</td>
</tr>
<tr>
<td class="text-center other-col">
<input type="checkbox">
</td>
<td class="email-col">
example#example.com
</td>
<td class="text-center other-col">
yes
</td>
<td class="text-center other-col">
no
</td>
</tr>
<tr>
<td class="text-center other-col">
<input type="checkbox">
</td>
<td class="email-col">
example#example.com
</td>
<td class="text-center other-col">
yes
</td>
<td class="text-center other-col">
no
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
You can find that an additional class other-col is added in the above code.
CSS
/* Styles go here */
.email-col {
/*width: 100%;
min-width: 1px;*/
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.other-col {
width:10%;
}
Add style for that cell
word-break: break-all;