question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delete rows from table

See original GitHub issue

Hi,

I am trying to delete rows (users) from the table based on an ID. When I check more than one box I get the ID of each select which I then add to a hidden input with the the value being the ids - example value="1,2" I then wrote function to delete the users from the database, but it is only deleting the first section in this example only userid 1 would be deleted from DB.

Here is an example of the delete user code.

function removeRow(){

    var url = 'remove-user.php';
    var id = document.getElementById("user-id").value;
    var data = 'userID=' + id;

    $.ajax({
            url: url,
            data: data,
            cache: false,
            error: function(e){
                    alert(e);
                },
            success: function () {
                var selects = $('#users-table').bootstrapTable('getSelections');
                    ids = $.map(selects, function (row) {
                        return row.id;
                    });

                $('#users-table').bootstrapTable('remove', {
                    field: 'id',
                    values: ids
                });                
            }
          });

    }

Do you have any other suggestion on how I could do this?

Again, it is not deleting all selections only the first one.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
RodrigoBurgosMellacommented, Jul 23, 2015

I implement the following function directly in the library and has worked very good

BootstrapTable.prototype.removeRow = function (params) {
    if (!params.hasOwnProperty('index')) {
        return;
    }

    var len = this.options.data.length;

    if ((params.index > len) || (params.index < 0)){
        return;
    }

    this.options.data.splice(params.index, 1);

    if (len === this.options.data.length) {
        return;
    }

    this.initSearch();
    this.initPagination();
    this.initBody(true);
};

how to use, like “updateRow”

$(“#your-table”).bootstrapTable(‘removeRow’,{index:1});

I hope serves them (sorry for my English)

0reactions
SaharAshFcommented, Mar 6, 2021

My Solution :

var $Table = $('#TableID');
var TmpTableData =$Table.bootstrapTable('getData');;
var TmpNewTableData = TmpTableData.slice();
TmpNewTableData.splice(Index, 1);
$Table.bootstrapTable('removeAll');
$Table.bootstrapTable('prepend', TmpNewTableData);
Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL DELETE Statement
The DELETE statement is used to delete existing records in a table. ... It is possible to delete all rows in a table...
Read more >
SQL - DELETE Query
The SQL DELETE Query is used to delete the existing records from a table. You can use the WHERE clause with a DELETE...
Read more >
How to Delete a Row in SQL – Example Query
In SQL, you can delete a row in a table by using the DELETE query and the WHERE clause. In the article, I...
Read more >
Delete rows and columns from a table
A fast way to delete a row or column from a table in Word Online is to click anywhere in the row or...
Read more >
How to Delete Records Using Delete in SQL [Updated]
The Syntax for Using the SQL Delete Command · The table from which we want to delete rows is specified in the table_name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found