twitter-bootstrap 在引导表中添加链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27819208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:05:26  来源:igfitidea点击:

Adding a link in bootstrap-table

twitter-bootstrapbootstrap-table

提问by Chan

I want to add a link to a column in bootstrap-table. How to do this?

我想在bootstrap-table 中添加一个列的链接。这个怎么做?

回答by William Weatherby

In your HTML table:

在您的 HTML 表格中:

<th data-field="snum" data-formatter="LinkFormatter">Computer</th>

in your javascript:

在你的 javascript 中:

function LinkFormatter(value, row, index) {
  return "<a href='"+row.url+"'>"+value+"</a>";
}

回答by Chan

I found the mechanism for this using the 'formatter'object. Below is an example formatter.

我使用'格式化程序'对象找到了这个机制。下面是一个示例格式化程序。

function identifierFormatter(value, row, index) {
    return [
            '<a class="like" href="javascript:void(0)" title="Like">',
                value,
            '</a>'].join('');
}

Basically to use this, it has to be added as an HTML data attribute to the Table Header.

基本上要使用它,它必须作为 HTML 数据属性添加到表头。

<th data-field="identifier" data-align="right" data-sortable="true"  data-formatter="identifierFormatter">Identifier</th>

回答by FelipeFalanque

html

html

<table id="table_exemple" data-toggle="table" data-pagination="true" >
    <thead>
        <tr>
            <th data-field="id">Id</th>
            <th data-field="name">Nome</th>
            <th data-field="action" data-formatter="ActionFormatter">Details</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

javascript

javascript

var bootstrap_table = $('#table_exemple');

function AddRow(obj){
    bootstrap_table.bootstrapTable('insertRow', {
        index: 0,
        row: {
           id: obj.id,
           name: obj.name,
           action: obj.id
        }
    });
}

function ActionFormatter(value) {
    return '<a href="javascript:void(0)" onclick="Details('+ value +')">Details</a>';
}

function Details(id){
    ...
}