Check record
Check record

Good afternoon.
I have a datatable that loads name and code and a button.
If in the name and code field there is a DB value, if it does not exist, I set a code 0 and name "Available"
I want to disable the button when there is a record and leave the button enabled when it does not exist, that is, code = 0 and name = 'Available'. But there is a question about it ... I have my name and my session code that I'm logged in and I need to do this check, that is:
If there is a line in the table with my code and my name, I leave the button enabled and disable all others (the other existing codes and those that do not yet have codes).
How to do this in datatable?
Replies
You could use
columns.render
to display the HTMl for the row and add the disabled attribute. Or you can usecreatedRow
orrowCallback
(if the data can change). If you still need help please build a simple test case showing what you have and how you are creating the buttons. Then we can provide more specific help.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
So Kevin.
It is difficult for me to create a new one, because I need to have the connection with BD, to do the process correctly ...
The fact is ... I need to know if there is a record before closing the datatable, I see no other way. If so, when I load the page I do the query and return if there is or not stop there when loading the datatable I do these actions.
Sorry, I don't understand what you are doing.
Is the button, the code and the name all in one row?
If you want to disable a button, that is in the row, based on other data in the row then use one of the options I provided above.
Kevin
Come on.
I am connected with my user, where I receive the user name and code per session, for example:
My code is 1 and my name is Lau.
After that, I have a datatable with code, name, button. In this datatable I carry 10 lines.
In the query of the BD that returns the data to the datatable, I return my code 1 and my name Lau (if I am registered in this table), I bring code 2 and name Kevin, for example and the other 8 lines, I load it in white .
What I want is ... If my code = session code exists in the datatable, it enables the button and disables all other loaded buttons.
If in the datatable there is no code = my session code, it will bring all enabled buttons.
Where are the buttons? In the rows, are you using the buttons extension or your own buttons?
You can use the
filter()
API for this. Maybe ininitComplete
.Seems like you could use Javascript variables to create a test environment with the session name/code and some example rows and the buttons. Then use
data
instead ofajax
to load the data.Kevin
I'll try to create a perfect example here and send it.
Thanks Kevin
Not sure it has to be a perfect test case
Based on my understanding (which may be way off) of what you want I started this test case. Maybe it will help you provide a more complete test case we can help with or maybe it will be enough for you to build your solution.
http://live.datatables.net/jajifugo/1/edit
Kevin
Good afternoon Kevin.
I made an exact example of the case. See the link.
The code and name of the session I associated the javascript variable as suggested, so here we go.
The example is:
The logged in user (code session and name session) can be listed in the datatable.
If the datatable loads the code and name of the code session and name session, it leaves only the button related to its line enabled and the other buttons disabled.
If there is no code session and name session in the datatable and all are "AVAILABLE", leave all buttons enabled. If there is no code session and name session in the datatable, but there are other code sessions and other name sessions, leave only the buttons where the lines are "AVAILABLE" enabled.
https://lmneto.com.br/example/
Sounds like you might want to use the example code I provide in
rowCallback
to first get the count that matches your condition. Based on the match you can enable to disable the button as desired. If you still need help then I suggest using something like http://live.datatables.net/ so we can work on the code with you.Kevin
Good afternoon Kevin.
I had already done your example in much the same way.
Kevin, to be direct, look at this:
If the code for my session code exists in the datatable, it only enables the button on this line and disables all others.
If in the datatable there is no code for my session code, it enables all others, as long as they have the name AVAILABLE.
Understood !? That's it!
Does that mean your code is working?
Kevin
It doesn't work Kevin .... I don't think you understand.
His example, he disables or enables everything! That's not what I want!
If the datatable has the same code as the session code, it disables all buttons and leaves only the button for the existing code enabled.
If there is no code in the datatable equal to the session code, it enables all buttons.
If the datatable does not have the same session code and there are other codes and names other than AVAILABLE, it disables all buttons that are different from AVAILABLE and enables only those that contain the name field "AVAILABLE".
Can you provide a test case sowing this please? Its difficult to help troubleshoot a problem when there isn't code to look at.
Kevin
Follow the link:
http://live.datatables.net/gosehoto/1/edit
Note .... Code Session 33 is Lau.
It exists in the datatable too. Thus, only the button related to this line should be enabled.
If a code session 33 does not exist in the datatable, enable the buttons only if they have the name "AVAILABLE", Kevin must be disabled.
Thanks!
I provided an example of one way to do this using
filter()
, as I show above, in therowCallback
. Here is the example:http://live.datatables.net/jajifugo/1/edit
An
else if
needs to be added for this condition. I'll let you try coding this part.Kevin
You are saying rowCallback but you are using initComplete
I did not understand ??????
Sorry, that was my original example. Check this out:
http://live.datatables.net/coguxuve/1/edit
Kevin
Kevin, eu acredito que seja isso que falta:
Not sure if that means its working or not. If not please update the test case so we can help.
Kevin
I think it's it:
http://live.datatables.net/coguxuve/2/edit
Thank you very much Kevin for your help and willingness.
God bless !