gpt4 book ai didi

javascript - Bootstrap table Js 中的 data-sort-name 是如何工作的?

转载 作者:数据小太阳 更新时间:2023-10-29 05:05:34 31 4
gpt4 key购买 nike

我正在使用以下库:http://bootstrap-table.wenzhixin.net.cn/documentation/

我将 json 对象加载到这个工作正常的表中,但现在问题来了。我希望能够对列进行排序。

我的 Json 布局如下:

[{"Total": 12345.56, "Name": "Monkey1", "TotalFormatted": "$ 12.345,56"},{"Total": 13345.56, "Name": "Monkey3", "TotalFormatted": "$ 13.345,56"},{"Total": 11345.56, "Name": "Monkey2", "TotalFormatted": "$ 11.345,56"}]

<table id="test" data-page-size="10" data-pagination="true" data-unique-id="true" data-show-footer="false">
<thead>
<tr>
<th data-field="Name">Name</th>
<th data-field="TotalFormatted" data-sort-name="Total" data-sortable="true" data-align="right">TotalFormatted</th>
</tr>
</thead>
</table>

我想显示 TotalFormatted 数据,但我想使用 Total 属性对该列进行排序,因为 TotalFormatted 不能用于此目的。在文档中我看到了以下内容:

data-sort-name : Provide a customizable sort-name, not the default sort-name in the header, or the field name of the column. For example, a column might display the value of fieldName of "html" such as "abc", but a fieldName to sort is "content" with the value of "abc".

但是数据是如何排序不正确的,有没有人经历过这个或者我误解了什么?

最佳答案

实际上 data-sort-name 不是那样工作的。 data-sort-name 选项的主要目的是控制表数据的默认排序。

要使 data-sort-name 选项使用默认排序,它需要指向表中列的 data-field 属性之一。

注意:简而言之,data-field 就像是在每一列中添加一个 id,data-sort-name 选项指的是对表格进行排序正在加载。

为了更好地理解这一点,这里有一个代码来自 Bootstrap site 的示例

  • 尝试将 data-sort-name 更改为 data-field 列值之一并执行代码,您将理解我上面刚刚解释的内容。<

HTML 代码:

<table data-toggle="table"
data-url="https://api.github.com/users/wenzhixin/repos?type=owner&sort=full_name&direction=asc&per_page=100&page=1"
data-sort-name="stargazers_count"
data-sort-order="desc">
<thead>
<tr>
<th data-field="name"
data-sortable="true">
Name
</th>
<th data-field="stargazers_count"
data-sortable="true">
Stars
</th>
<th data-field="forks_count"
data-sortable="true">
Forks
</th>
<th data-field="description"
data-sortable="true">
Description
</th>
</tr>
</thead>

现场演示 @ JSFIDDLE:http://jsfiddle.net/dreamweiver/ptxj8Lao/

关于javascript - Bootstrap table Js 中的 data-sort-name 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31518321/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com