RETURN DEF
RETURN DEF

Good afternoon.
As I do, if the clicked button is create it sends a fixed value A in a given field, if it is update, it takes a value B and if it removes, it takes a value C.
Any tips, please !?
This discussion has been closed.
Replies
Are you using Editor for this? If yes maybe the
dependent()
API is what you are looking for.If this doesn't help please provide more details and context around what you are wanting to do. Do you have code you can share that will help us understand?
Kevin
Hi kthorngren.
I don't have a code ready.
But the explanation is standard. In the edit and create button of the datatable, when I call the action create I wanted to pass a fixed value in a field and when I call the action edit I want to pass another fixed value for this same field.
Does the
set()
to set the field value do what you want?Kevin
Good Morning. How do I use it within this section?
You would do that with
preOpen
, and useset()
as Kevin suggested - see here: http://live.datatables.net/qopumida/1/editColin
Hi Colin, good morning.
Yesterday I was without internet, fell.
I'm seeing now.
I think that's it, buddy.
Thank you very much saw.
God bless you !
Colin, I tested it here. I don't think it's going to do what I need.
I am looking to do the following.
In the delete button, I don't want to use action remove. I'm entering extend: selected
Then I want to instead of deleting the record permanently, just make an update in a field. I don't want to have to create a new editor_delete for example to do this.
One option is to take the server script and when the
action
isdelete
execute the same code that updates records. Another option is to create a customer delete button similar to this example:https://editor.datatables.net/examples/api/duplicateButton.html
Kevin
kevin, I believe that is it, right, with respect to your example.
Perfect !
Thank you saw .... I'm trying to understand the features of this datatable to see what I still do.
Thanks again
Taking advantage, if I am told to open a new discussion, I will, but if you can clear this doubt here, how do you not count the number of records in the page info, when a field is hidden?
I'm using:
rowCallback: function (row, data, index) {
if (data ["clipacstatus"] === "E") {
$ (row) .hide ();
}
},
I don't know if it's the best way, as it is included in the page info count.
You can't really 'hide' rows, all you can do is remove them with
row().remove()
. The method you were using withhide()
would just hide it without DataTables knowing, so that's why it's being counted still.Colin
For clarity of people searching and reading threads its best to open new threads if the subject is different. But I'll answer here.
This is a jQuery method. Datatables doesn't know anything about table modifications when using jQuery or other non-Datatables methods/APIs to update the table display. I would use a Search Plugin for this. It would be a simple one, something along the lines of this:
I didn't test this or verify the syntax but it should be close. Place this before your Datatables init code.
Kevin
I had tried.
If I use:
rowCallback: function (row, data, index) {
if (data ["clipacstatus"] === "E") {
$ (row) .remove ();
}
},
The line keeps showing. If I use:
rowCallback: function (row, data, index) {
if (data ["clipacstatus"] === "E") {
row (). remove ();
}
},
the table does not load
I will try more than a few ways .... these did not work ...
Look at the browser's console for errors. Suspect you will see an error with
row (). remove ();
.row
is thetr
element not an API. Something like this should workthis.api().row( row ).remove()
. But I'm not sure that removing rows from withinrowCallback
is a good idea.Tell us what your goal with hiding/removing these rows is. Do you want to permanently remove them form the Datatable or just filter them? Do these rows need to be removed only at initialization or can table changes cause them to be removed at other times?
Giving us these details will help us to give you the best option.
Kevin
So.
I don't want to use the remove method to permanently delete the db record.
I want to delete it, change the status of a field to E. This is already being done correctly with the help you gave above.
What happens now is that, when loading the table, I don't want to load the records with these E fields. I know that if I set this on select I can, but I always read the last code for when I insert a new one , it increment 1 more. I don't know if I could explain it well.
Or, if there is a function that, when I use the create method, it takes the last code and increments + 1, it would help.
The
row().remove()
method removes the row from the client Datatable not from your server database.The best place for this is to update your server database query to exclude data with
E
.Not sure what you are trying to do.
Kevin
Come on, I'm bad at explaining by typing.
I have 13 records (13 lines) id 1, codc1, id 2, codc2 and so on.
First: I don't delete it from the database, I just change the clipacstatus = 'E' field. This is already OK and working.
Second: when loading the table, I want it to load without these fields clipacstatus = 'E'.
Third: when I use create, I read the last codc in the table and increment + 1 to open the editor with the codc assuming this value.
If I remove the row from the table with remove () and I use create, it will read the last code in the table, however, it may be that this last code exists, it was only removed from the table.
What I need to do, in summary, is not to delete it from the database, however, not to show it in the datatable, and when I create a new record, it takes the last value entered + 1.
Thanks for the explanation. I think I understand. If you want to get the last code in the database then you will need to use a jQuery ajax() request to a server script that can fetch and return that code.
Kevin
So. Therein lies the problem. I can do this directly in the select that I use to load the datatable.
The point is, I can't remove the lines with clipacstatus = 'E', I'm just managing to hide them. And if I hide it, the pageinfo count is wrong.
If I force the line with clipacstatus = 'E' to be removed directly from the datatable, when creating a new record, it may not increment the last correct code.
I need all these sequences to take effect.
Thats why I suggested using an ajax request that fetches the last code from the DB when you need it. Unless you have a slow connection to the server it shouldn't be a much of a delay to do this. Otherwise you will need to find a way to keep track on the client which could complicate the code and make it difficult to troubleshoot or make changes later.
As a side note you might be interested in this Soft Delete example:
https://editor.datatables.net/examples/api/softDelete.html
Kevin
My solution was:
rowCallback: function (row, data, index) {
if (data ["clipacstatus"] === "E") {
$ (row) .hide ();
i ++; ///// there are a number of hidden lines
}
},
"infoCallback": function (settings, start, end, max, total, pre) {
var api = this.api ();
var pageInfo = api.page.info ();
return 'Showing from' + (pageInfo.start + 1) + 'to' + pageInfo.end + 'from' + (pageInfo.recordsTotal-i) + 'records';
},
and in the section above (pageInfo.recordsTotal-i) I subtract the total amount of records minus the total value of hidden lines.
So I don't need to change anything in my bd select or do any other treatment or apply any remove () that interferes with other methods I use.
No, it doesn't work ... with hide he counts the hidden lines, even in the pages, my previous solution would be perfect if he didn't take this issue into consideration, but he still counts the hidden records.
Like I said Datatables doesn't know anything about this. In its data cache it still has those rows visible. Paging, searching and sorting will not behave as expected.
Kevin
Great.
So a single question can be helped in this matter.
How do I load the datatable without the lines containing clipacstatus = 'E'!?
I don't want to and I can't handle this in the select of the db query, I need to do it directly in the datatable.
You can use the
ajax.dataSrc
as a function to manipulate the data. I think you will need to make sure to return{"data":[]}
from your custom delete button for the row to be removed from the Datatable. Look at theAjax Data
tab of the Soft Delete example I linked to earlier.Kevin
Kevin, forget about the delete button. This is already ok.
All of that is already OK.
The only question I ask now is:
How do I load the datatable without the clipacstatus = 'E' records? But, directly in the datatable functions, not in the db select!
Did you look at the
ajax.dataSrc
docs? There is an example of using it as a function to manipulate the data.Kevin
Ah .... now I got a friend ...
Thank you, my ... I was fumbling here with so much information.
Thanks for the help and patience.
Kevin, which is faster, a select Max (field) or a select top 1 camp order by desc or another option !?
Good Morning.
I did according to the proposal.
In the select that I generate data from db for datatable, I already generate MAX (cod) + 1 to take to json the value of the last code. Perfect!
I can already get him in this function proposed by you:
table_CP.on ('xhr', function () {
var json = table_CP.ajax.json ();
var ultcod = json.data [0] .ultcod;
});
Now, I need to put it within this function that you passed. As !? He doesn't accept !!!!
editor.on ('preOpen', function (e, mode, action) {
if (action === 'create') {
editor.set ('clipaccod', ???????);
}
})