How to display the icon in the table
How to display the icon in the table
izumov
Posts: 178Questions: 14Answers: 0
My task is to develop a shopping cart page for the online store .To do this, I need to have icons with + and-in the last two columns of the table.When you click on that quantity of goods of the given string, or increased or decreasing respectively. Tell me how to organize the display of icons.
This discussion has been closed.
Replies
I was hoping that I would work data column rendering together with server processing and I got this code,
'''
$(document).ready(function()
but the code but it does not work.
How do I change the code to make it work correctly?
I don't see anything that you are trying to do in the last two columns with
+
and-
. Here are a couple of examples with buttons rendered into particular columns. Maybe one of the will help:Using
columns.defaultContent
:http://live.datatables.net/xijecupo/1/edit
Using
columns.render
:http://live.datatables.net/qemodapi/1/edit
If these don't help then please build a simple test case so we can help you with your code.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
sorry, but I have never seen an example of a combination of server processing and rendering code. Is that possible?
my attempt to combine them, the code I gave in the first message was not successful
I tweaked the code and now I have displayed in column 9 text And I would like to see there the image of the icon . What is my mistake?
'''$('#goods').DataTable( {
What happens?
Looks like you have a syntax error with this:
return "< img src=images/sort_asc.png>"
. You need quotes aroundimages/sort_asc.png
. Something like this:return '< img src="images/sort_asc.png">'
.Kevin
fixed code
'''
"columnDefs": [
{
'''
taking into account your advice still displays the text and not the icon
If you place that code (
< img src="sort_asc.png"
) directly into your HTML what happens? Is it the same result?Try removing the space here
< img
to look like this<img
.Kevin
Kevin Thanks so much.Code works as it is necessary now displays the icon.
now I need to process the mouse click in the columns with icons as their meaning is different adding or reducing the product I need to know in the handler column in which there was a mouse click in the manual I could not find the desired section.I tried to link the event of clicking a particular column using code.
I think there is a more elegant solution to the problem. Please suggest the solution.
I can't understand why in the code
an error appears
goods101.js:41 Uncaught TypeError: Cannot read property '0' of undefined
Where is the error?
I don't think
'tr td:eq(9)'
is working the way you expect. I believe it is a selector for only onetd
in the table, the 9th one. Looking at the jQuery :eq() Selector docs the example indicates the usingtd:eq(9)
is not reset each row.My suggestion is to use
columns.className
to assign a class to column 9 and use that as the selector, for example'tr .col9'
. Here is an updated example using your code:http://live.datatables.net/telubuqe/1/edit
If you continue to have the
Cannot read property '0' of undefined
error we will need to see your page or a test case replicating the issue to help debug. You can update my example if you want.Kevin
what's wrong with this code ? Icons are no longer displayed and still does not trigger the event of clicking the mouse on the column
Two problems; first is targets is misspelled, second you should combine all the options for target 9. Like this:
Kevin
Here is the entire code initiation
Now icons are displayed and the event handler does not work. Is there a problem?
Looks like you might need a space here
'tr.position'
, like this'tr .position'
.Kevin
With this amendment, the handler gets triggered but error remained.When trying to output data[0]
To help further we would need to actually see the problem. Please provide a link to your page or a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Your example code works in the example I posted. There is something specific to your environment or data.
You could use some console.log statements to troubleshoot. Try this:
What do you get? You can do the same in my example to compare.
Kevin
my test case
http://montaj.vianor-konakovo.ru/goods9997.html
I debug pressing the plus icon.
I have in my console
Uncaught TypeError: Cannot read property '0' of undefined
at HTMLTableCellElement.<anonymous> (goods101.js:45)
at HTMLTableSectionElement.dispatch (jquery-3.3.1.min.js:2)
at HTMLTableSectionElement.y.handle (jquery-3.3.1.min.js:2)
Can you help me?
I'm not sure why what you had didn't work but it looks like this should:
Kevin
in this case the code is working properly thanks for the tip.Tell me how to display the icons in the previous column. My code has errors
I can't understand why the icons in column 8 are not displayed.Can you tell me what's going on?
Where do I make a mistake?
how to change the code to display icons in both 8 and 9 column?
currently, icons are only displayed in column 9
more precisely, nothing is displayed because the debugger shows an error on the sign { when declaring a class in column 8
Your first "render" function is lacking a closing bracket.
Made changes now the code looks like this
Now displays the icons in columns 8 and 9, but the handler event onclick in column 9 has stopped working handler for mouse click in column 8 is working
about any errors the debugger will not signal. Why doesn't the mouse click handler on column 9 work ? What's wrong ?
Doesn't look like you updated your test case. It could be the
.off()
. I had that for testing your page and should have removed it. Both should look like this `$('#goods').on('click'``. If this doesn't help then reverse the order of the click events to see if the problem changes columns.Kevin