Skip to content

How to add attributes to TD/TR from new row of bootstrap-table?

Currently I have project using bootstrap-table. I have problem when add new row with attribute. To insert new row I used code below:

    var row = ({
                  name: "test name",
                  type: "Organisation",
                  status: 'Active',
                  action: ''
     $('#table-home').bootstrapTable('append', row);

I want to add attribute also to the new row. I am currently used jQuery like below:

                var newRow = $('#table-home tr:last');
                var firstTd = newRow.find('td:first');
                var lastTd = newRow.find('td:last');

But that’s attribute will lost after I insert/append new row again. After I sort the table my attributes will lost too. actually how to add attribute to new row of bootstrap-table?



I already read all documentation and I can not found how to do that. But today, after I experiment use console.log to check what object/data inside every row in bootstrap-table I solved my problem with code below:

            const row= ({
                    name: RiskName,
                    type: "Risk Type",
                    status: 'Active',
                    action: '',
                        "type": "Risk Type",

_data is data attribute for the row (example <tr data-id="val">)

_action_data is data attribute for the column which named action(exampled result <td data-tag="val">)

7 People found this is helpful