TechMaster TechMaster - 1 year ago 122
Javascript Question

How to get complete data from (html) bootstrap table when pagination is turned on

I am using bootstrap table in my web page and want to get complete textual data from all table cells, when pagination is on. I have tried the following method and it returns all the data:

var data = $('#' + tableID).bootstrapTable('getData')

Now when i traverse
object to get value for every cell it works fine but, for those cells which have some nested html , for example:

<td class="danger">cell 4</td>
<a href="">google</a>

Now, in this case, i want to get value for second cell as google but it returns me whole html as

<a href="">google</a>

Any idea, how i can get only textual value.

I can't do any server side operation, I have to achieve this using javascript/jquery. I have also tried using jquery:

function getColData(tableID,colIndex) {
var colArray = $('#' + tableID + ' td:nth-child'+'('+colIndex+')').map(function(){
return $(this).text();
return colArray

it returns data correctly but only which is visible on active page and i want all the data.

Answer Source

Since the actual data is coming in as a string, I don't think bootstrap-table can't differentiate it from the other data. The simple solution I can think of is to use substring() to extract the data from the cells that contain custom html.

The alternative is to go through the generated table <td> and use text() to get the text data from the cells.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download