get id of accordeon button in a table
get id of accordeon button in a table
tsurubaso
Posts: 32Questions: 8Answers: 0
Hello,
I you are all well!
I have not an error but... I don't really know how to do.
I have a table that display company name and code I use the code to find the stock value.
I can get easily the data inside the table.
But I am searching for the id of the pushed button.
$(this).attr('id');
does not work.
The code is here
~~~~~~~~~~~~~~~~
{
data: null,
title: 'Action',
dom: 't',
render: function() {
return `<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Search mode
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" id="btnp1" onclick="mouseDowCodeSearchEntreprise()" >Intraday 1min</a></li>
<li><a class="dropdown-item" href="#" id="btnp2" onclick="mouseDowCodeSearchEntreprise()" >Intraday 5min</a></li>
<li><a class="dropdown-item" href="#" id="btnp3" onclick="mouseDowCodeSearchEntreprise()" >Intraday 15min </a></li>
<li><a class="dropdown-item" href="#" id="btnp4" onclick="mouseDowCodeSearchEntreprise()" >Intraday 30min</a></li>
<li><a class="dropdown-item" href="#" id="btnp5" onclick="mouseDowCodeSearchEntreprise()" >Intraday 60min</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" id="btn1a" onclick="mouseDowCodeSearchEntreprise()">Daily</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" id="btn1b" onclick="mouseDowCodeSearchEntreprise()">Weekly</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" id="btn1c" onclick="mouseDowCodeSearchEntreprise()">Monthly</a></li>
</ul>
</div>`;
}
}
//The mouseDowCodeSearchEntreprise()
function mouseDowCodeSearchEntreprise( event){
var id = $(this).attr('id');
console.log(id)
$('#searchTable tbody').one( 'click', 'button', function () {
var tr = $(this).closest("tr");
var data = $("#searchTable").DataTable().row(tr).data();
console.log(data[0]);
var id = $(this).attr('id');
console.log(id)
//window.electron.ipcRendererWithValue('myomyo',[data[0],id]);
} );
};
Answers
You can use
row().data()
to get the data for a row. If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.Cheers,
Colin
I use electron. I learned the web a wired way. I can send you a fiddle. But this is a nightmare. I can accede the data of the table without problem, but i try to get the id of Button. I will search again... Thanks for you always good reactivity
You have a click event for this
button
:This button doesn't have an ID.
Are you wanting the ID of what is clicked in this list?
One problem with this is you will have many elements on the page with the same ID. HTML requires the ID to be unique.
If you need help please provide a test case with an explanation of exactly what you are looking for. It doesn't need to be electron. You can build a simple test case using the Datatables JS BIN environment to show what you are trying to do with the click events:
http://live.datatables.net/
Kevin
Kevin,
I am extremely thankful for all your efforts. I am an Hobbyist. People Golf, I do code. I do love datatables, but I was not ready to kill my weekend. I just killed Saturday. I tried classes by the way. Not working either. I am using an other way. reusing already written thing. I will surely ask for help in the future, and I will surely be thankful again for the team of datatables.
nice sunday