RETURN DEF

RETURN DEF

lauromnetolauromneto Posts: 83Questions: 0Answers: 0

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 !?

«13

Replies

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0
    edited June 10

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    Does the set() to set the field value do what you want?

    Kevin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0
    edited June 11

    Good Morning. How do I use it within this section?

    action: function(e, dt, node, config) {
        editor.edit(table.row({
            selected: true
        }).index(), true);
        editor.disable();
        e.preventDefault();
        editor.edit($(this).closest('tr'), {
            title: 'Delete Record',
            buttons: ['Delete', {
                text: 'Close',
                action: function() {
                    this.close();
                }
            }],
        });
    },
    
  • colincolin Posts: 8,995Questions: 0Answers: 1,501

    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.

    You would do that with preOpen, and use set() as Kevin suggested - see here: http://live.datatables.net/qopumida/1/edit

    Colin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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 !

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    One option is to take the server script and when the action is delete 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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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

            {
                extend: "selected",
                text: 'Delete',
                className: 'btn-red',
                action: function ( e, dt, node, config ) {
                    // Start in edit mode, and then change to create
                    editor.disable();
                    editor
                        .edit( table.rows( {selected: true} ).indexes(), {
                            title: 'Delete',
                            buttons: ['Delete', { text: 'Fechar', action: function () { this.close(); } }]
                        } )
                        .mode( 'edit' );
                        editor.set('clipacstatus', 'E');
                }
            },
    
  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • colincolin Posts: 8,995Questions: 0Answers: 1,501

    You can't really 'hide' rows, all you can do is remove them with row().remove(). The method you were using with hide() would just hide it without DataTables knowing, so that's why it's being counted still.

    Colin

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    Taking advantage, if I am told to open a new discussion, I will

    For clarity of people searching and reading threads its best to open new threads if the subject is different. But I'll answer here.

    $ (row) .hide ();

    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:

    $.fn.dataTable.ext.search.push(
        function( settings, searchData, index, rowData, counter ) {
    
            if ( searchData.clipacstatus === 'E' ) {
                return false;  // Hide row.
            }
            return true;  // Show row.
        } 
    );
    

    I didn't test this or verify the syntax but it should be close. Place this before your Datatables init code.

    Kevin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    I will try more than a few ways .... these did not work ...

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    the table does not load

    Look at the browser's console for errors. Suspect you will see an error with row (). remove ();. row is the tr element not an API. Something like this should work this.api().row( row ).remove(). But I'm not sure that removing rows from within rowCallback 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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147
    edited June 12

    remove method to permanently delete the db record.

    The row().remove() method removes the row from the client Datatable not from your server database.

    when loading the table, I don't want to load the records with these E fields.

    The best place for this is to update your server database query to exclude data with E.

    Or, if there is a function that, when I use the create method, it takes the last code and increments + 1, it would help.

    Not sure what you are trying to do.

    Kevin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    $ (row) .hide ();

    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

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    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 the Ajax Data tab of the Soft Delete example I linked to earlier.

    Kevin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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!

  • kthorngrenkthorngren Posts: 9,314Questions: 25Answers: 2,147

    Did you look at the ajax.dataSrc docs? There is an example of using it as a function to manipulate the data.

    Kevin

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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 !?

  • lauromnetolauromneto Posts: 83Questions: 0Answers: 0

    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', ???????);
    }
    })

Sign In or Register to comment.