如果通过URL加载数据,是否可以在行(TR)上提供唯一ID?

时间:2015-03-26 19:38:14

标签: twitter-bootstrap

我使用此插件:http://bootstrap-table.wenzhixin.net.cn/

我通过URL加载数据并返回以下JSON格式:

{
   "total":1,
   "rows":[
      {
         "id_account":"1",
         "email":"cool@magikweb.ca",
         "first_name":"Vincent",
         "last_name":"Morino",
         "type":"R\u00e9gulier ou personnalis\u00e9",
         "status":"Actif",
         "billing":"Non",
         "name":"Vincent Morino"
      }
   ]
}

我有什么方法可以以某种方式返回id_account,以便将其应用于<tr>

我在HTML表格上应用data-url="base-data.php?identifier=listing-users"并将其初始化为:

$('.table').bootstrapTable({
    pagination: true,
    sidePagination: "server",
    showColumns: true
});

HTML上下文:

<table id="listing-users" class="table table-striped table-hover" data-url="base-data.php?identifier=listing-users">
    <thead>
        <tr>
            <th data-field="name" data-sortable="true">Nom du contact</th>
            <th data-field="email" data-sortable="true">Adresse électronique</th>
            <th data-field="type" data-sortable="true">Droits d'accès</th>
            <th data-field="billing" data-sortable="true">Utilisateur à facturer?</th>
            <th data-field="status" data-sortable="true">État</th>
        </tr>
    </thead>
</table>

换句话说,我想放置标识行的任何内容,所以当它被选中时,我可以使用一个唯一的标识符。

我的第一次尝试是在前面提到的HTML上下文中的TR元素上添加data-field="id_account",但没有成功。

2 个答案:

答案 0 :(得分:0)

data-id-field会像这样继续使用表格标记:

<table id="listing-users" class="table table-striped table-hover" data-url="base-data.php?identifier=listing-users" data-id-field="id_account">
<thead>
    <tr>
        <th data-field="name" data-sortable="true">Nom du contact</th>
        <th data-field="email" data-sortable="true">Adresse électronique</th>
        <th data-field="type" data-sortable="true">Droits d'accès</th>
        <th data-field="billing" data-sortable="true">Utilisateur à facturer?</th>
        <th data-field="status" data-sortable="true">État</th>
    </tr>
</thead>

或者你可以在jQuery初始化中简单地指定它:

$('.table').bootstrapTable({
   pagination: true,
   sidePagination: "server",
   showColumns: true,
   idField: 'id_account'
});

更新2015-04-15

稍微更新一下,告诉你最后我在TR上没有data-id-field。我同时使用idFielduniqueIduniqueId写的是TR中的值,而不是idField

但是我的功能对我有用,因为我在本帖子时只使用idField来更新我的行(似乎只有updateRow函数正在使用它),就像我试图用它隐藏行,它不起作用。

所以,如果你想跟进问题,因为它会得到解决,你可以在这里:https://github.com/wenzhixin/bootstrap-table/issues/583

答案 1 :(得分:0)

在此之后:https://github.com/wenzhixin/bootstrap-table/issues/658 我发现选项data-unique-id有效并将标记直接应用到TR上。