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'); newRow.attr("data-catid",categoryName); newRow.attr("data-assetdetail_id",data); firstTd.attr("data-remove-link","#"); firstTd.attr("data-edit-link","#");
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?
Advertisement
Answer
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: '', _data:({"uniqueid":data.id, "key":0, "id":data.id, "status":"Active", "type": "Risk Type", }), _action_data:({"delete-link":"", "edit-name":RiskName, }) });
_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">
)