Remove rows: button or icon "onclick" remove all rows with the same value

Remove rows: button or icon "onclick" remove all rows with the same value

charallavecharallave Posts: 6Questions: 1Answers: 0

Hi,

I have a datatable with 100 million rows with columns: "url" (300.000 values) and "file" (100 million of values). I need a button or icon per row. On click removes all the rows with the same "url" value. Thanks!

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Given the number of rows, this would be server-side processing, so you'll need a script on the back-end that would delete the records out of the database. You could use columns.render to put the button on the row, see example here.

    Colin

  • charallavecharallave Posts: 6Questions: 1Answers: 0

    Thank you!

    But... I don't want to delete the data in the server database, I just want to remove (or hide) the rows in the table.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    With serverSide, the data always comes from the server, so if you want the row removed, you'll need to remove it on the server itself. If you don't, the remove won't persist - as soon as you search, order or change page, that row will come back. You could keep an array of rows that have been removed, then on every draw see if those rows are present and remove them with row().remove(), but it'll get messy because pages will have odd lengths, and any page refresh would bring all those rows back again regardless.

    Colin

  • charallavecharallave Posts: 6Questions: 1Answers: 0

    Thanks again!

    And what about rows().remove()?

    Does it also delete the data on the server?

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    The row().remove() API works with client side processing only. If you are using server side processing, as Colin suggests, then this API won't work. You could use ajax.data as a function to send information to the server of what rows to filter in the the response. See this example.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    In addition to Kevin's comment, rows().remove() behaves similarly to row().remove() - it just allows you to remove multiple rows at the same time.

    Colin

  • charallavecharallave Posts: 6Questions: 1Answers: 0

    Thank you.

    On the other hand, I have a table with millions of records searching with wilcards which is very slow. I'm testing sphinx to speed up searches. Is it possible to use php + datatables + sphinx?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm not familiar with Sphinx, but provided it can respond with the information expected by DataTables, it should be fine. The protocol is discussed here. Also see examples here.

    Cheers,

    Colin

  • charallavecharallave Posts: 6Questions: 1Answers: 0

    Hi,
    I have half the solution, i would need to solve the other half ... :-)

    I have created an index.php with SQL SELECT using wildcards to a Sphinx service that returns a list (array) with all the IDs that I need to do (in ajaxfile.php) the query select * from table where value IN ($ myids). How do I send that list to ajaxfile.php?.

    Thanks!

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Do you mean that in index.php where your DataTables Javascript is being run, you have a list of ids which you want to send to the server (ajaxfile.php) and use that as the basis for your SQL query in that file?

    If so, you can send extra information to the server using ajax.data.

    Allan

  • charallavecharallave Posts: 6Questions: 1Answers: 0

    You're right!

    It works correctly like this:

    <

    script>
    $(document).ready(function(){
    $('#empTable').DataTable({
    'searchDelay': 1500,
    'processing': true,
    'serverSide': true,
    'deferRender': true,
    'serverMethod': 'post',
    'ajax': {
    'url':'ajaxfile3.php',
    "data": {"myids": ('70, 40,50 ')
    }
    },

    but it doesn't work when I try:

    "data": function (d) {
    "myids": ('$ myids')
    } ...

    Is it a syntax problem?

    Thank you!

Sign In or Register to comment.