简体   繁体   中英

Bootstrap table get data from selected row

I have created an bootstrap table (see image )

在此处输入图片说明

this table is populated by an mysql connection with php server side.

My problem is to get data from selected row in a table, i know I have to use function

bootstraptable('getselections')

But I receive this

getSelections: [object Object]

intead of this

getSelections: [{"Nation":"dad","Site":"-"}]

Please can you help me?

Full code here

<div id="toolbar">
            <button id="button" class="btn btn-default">getSelections</button>
        </div>
<table id="table" data-click-to-select="true" 
                data-toggle="table"
               data-toolbar="#toolbar"
               data-height="600"
               data-click-to-select="true" 
               data-url="db_list.php"
               data-search="true"
               data-pagination="true"
               >
            <thead>
            <tr>
                <th data-field="num"  data-checkbox="true" >#</th>
                <th data-field="Nation">Nation</th>
                <th data-field="Site">Site</th>
            </tr>
            </thead>

               </table>

<script type="text/javascript">
    var $table = $('#table'),
        $button = $('#button');

    $(function () {
        $button.click(function () {
            alert('getSelections: ' +  $("#table").bootstrapTable('getSelections'));
        });
    });
</script>

Refer Bootstrap Table getSelections example

It uses JSON.stringfy function. So you have to use as follow.

alert('getSelections: ' + JSON.stringify($("#table").bootstrapTable('getSelections')));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM