button function
button function
antoniocib
Posts: 277Questions: 62Answers: 1
hello guys, I'll explain my problem I created a column where I inserted a button, but now I don't know how to create a function that when this button is clicked changes the background color to the row, I also created a field in the mysql table (int ), you can help me I don't know how to do it, sorry if the text can be spelled wrong but I'm using a translator.
{data: null,
defaultContent: '<input type="button" name="" value="Ritiro">',
type: 'Ritiro'}
This question has accepted answers - jump to:
This discussion has been closed.
Answers
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
http://live.datatables.net/zunogaga/1/edit this is my table @colin
That doesn't run, I'm afraid.
Colin
Can i send my website where it run and u can see?
I updated one of my button examples to show how one way to highlight the row clicked:
http://live.datatables.net/yocaheli/1/edit
Note the CSS included in the CSS tab.
Kevin
Okay kevin, for this its okay but this button must to sent it to database because if i reload the page the background leave
You asked how to highlight the row which is what I showed. The click function shows how to get the row data. If you want to send the row ID to the DB then use jQuery ajax to send the ID to the server script to update the DB.
Or are you wanting to use the Select extension? With select you can use
ajax.reload()
and Datatables will re-select the rows after the data is loaded. You need to use therowId
option for this to work.Maybe you can describe in more detail what you are trying to do.
Kevin
So, I need to create this button that once pressed highlights the row and returns a data to the database which when loaded another time the datatable remains highlighted
How will you know if the row is to be highlighted when loaded at another time? Are you using a field in your DB for this?
Kevin
If you don't need to persist the highlights in your DB you can use the Select Extension as I mentioned above. Here is an example:
http://live.datatables.net/yocaheli/3/edit
Note that I added the select extension JS and CSS. Changed the click event to select the row. Added
rowId
for the reload to re-select. Added a button to executeajax.reload()
. You will see the selected rows are reselected after ajax.reload().Kevin
Yes, kevin i add to my database a field where i use for this (is an field "int")
Because i need to reload this table in another page for this i need than this button turn a data on database and when this table is load read the data on this row and evidence the row
When you reload the table you can use either
createdRow
if the data is static orrowCallback
if the data can change to highlight the row based on a value within the row. The docs have examples.Kevin
How to do a button than send eg:"1" for pressed "0" not pressed
Example :
If button is "1" row evidence
else
not evidence row
Sounds like you want a checkbox not a button. A checkbox is a toggle.
Or you can change the toggle the value ("1" or "0") for the row each time the button is clicked.
Kevin
Yes kevin, sorry but im so bad
If you are using Editor then this example will get you started:
https://editor.datatables.net/examples/api/checkbox.html
Kevin
Too add background color when is checked? How to do.
Use the
rowCallback
function. See this example:https://datatables.net/examples/advanced_init/row_callback.html
Kevin
When i check the checkbox console turn me this error:
This my code:
https://damoratraffico.netsons.org/dioca/scrivania1.html
Solved, i dont declare in the label the field : active, now i need only to change the background color of row when the check box is checked
I including in this mode createdRow for background color of the row, but dont work..
createdRow: function ( row, data, index ) {
if ( data[11] == 1 ) {
$('tr', row).eq(11).addClass('highlight')
}
},
@kthorngren
If you are using objects instead of arrays, ie, using
columns.data
, then you need to access the data using object notation instead of array notation. For example,Kevin
http://damoratraffico.netsons.org/forse1/scrivania1.html
i leave my code for check it, but dont work this way..
You are using
createdRow
which only runs when the row is first created. I suggested usingrowCallback
because it runs each time the row is redrawn on the page.Add your createdRow code to the rowCallback function you have.
Kevin
sorry kevin for the time you are wasting but you give me an example that translating I can't understand
i think the problem is too in.css
If you inspect your table you will find that the row with the checkbox that is checked does not have the class
highlight
. You have the wrong selector. Instead of$('tr', row).eq(11).addClass('highlight')
try$(row).addClass('highlight')
.Kevin
Thanks Kevin works but the css dont work
this is the result:
but my css is:
tr.highlight {
background-color: #00FF00;
}
Use the browser's inspector tool to see what styles are being applied. Simply using
tr.highlight
probably won't work. Take a look at my first example to see what I used. You should be able to override the style you don't want by replicating the selector in your custom CSS.Kevin