Search code examples
javascripthtmltwitter-bootstrappaginationbootstrap-table

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 data 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>
   <td>
   <a href="https://www.google.com">google</a>
   </td>

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

 <a href="https://www.google.com">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();
       }).get();
       return colArray
    }

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


Solution

  • 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.

    http://jsfiddle.net/vwg5Lefz/

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

    http://jsfiddle.net/n0djy60v/