JqGrid sorting on href tag and not content
I'm currently trying out the jqGrid plug-in. Everything is working well expect for sorting on a specific column.
I have an existing table that I'm trying to apply the plug-in to.
<script type="text/javascript">
$(document).ready(function () {
tableToGrid("#myTable", {})
});
</script>
<table id="myTable">
<thead>
<tr>
<th>
Web Site
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="http://www.jsmith.com/4093">Hello</a>
</td>
</tr>
<tr>
<td>
<a href="http://www.jsmith.com/4094">Bob</a>
</td>
</tr>
<tr>
<td>
<a href="http://www.jsmith.com/4093">Loblaws</a>
</td>
</tr>
<tr>
<td>
<a href="http://www.jsmith.co开发者_运维问答m/4093">Wahoo</a>
</td>
</tr>
</tbody>
</table>
When I sort the column, the order comes up as
Hello, Loblaws, Wahoo, Bob
instead of
Bob, Hello, Loblaws, Wahoo
It looks like it is sorting the href tag and not the content.
Very similar to this problem (just a different plug-in) - Table sorter issue with content
The reason why you have so strange sorting oder is that in the way how you use jqGrid currently you create the grid having one column with string data. The string data will be:
"\n <a href=\"http://www.jsmith.com/4093\">Hello</a>\n "
"\n <a href=\"http://www.jsmith.com/4094\">Bob</a>\n "
"\n <a href=\"http://www.jsmith.com/4093\">Loblaws</a>\n "
"\n <a href=\"http://www.jsmith.com/4093\">Wahoo</a>\n "
How you can see the string which contain "Bob" substring has "4094" before. So the string will be the last string in the sort order.
You can improve the situation using the second options
parameter of tableToGrid
, but the best way would be to make clear separation of the information about the text displayed in the column (like "Bob", "Hello") and so on from the url data. Then the sorting on the columns will be exactly like you want. So it is better don't use tableToGrid
function for your data and create jqGrid in the direct way.
Because I don't know from which source you get the information about the url for the texts it is difficult to give you some recommendation for the best implementation. You can find examples how to construct links in the jqGrid here and here. I think that you can easy modify the examples for your purpose.
You can go for custom formatter custom_formatter.It will help you in case of sorting on basis of href content as in jqgrid ,i feel it is not possible.
Alternative, you can pass one more column containing href content and sort the href column based on this,though it's not preferred.
tableToGrid doest not sort your table, it only turns your table into grid. For client side sorting, this may help you. jqGrid sorting on client side
精彩评论