Реализовать двойную сортировку, учитывая одинаковую звездность отеля. Если есть,например, три отеля с одинаковой звездностью, то эти отели отсортировать по имени.
Пока есть сортировка просто по звездности.
Реализация на Grails.
HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
| <html>
<head>
<title>Результаты поиска</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main" />
<style type="text/css">
.title {
margin: 1em 0;
padding: .3em .5em;
text-align: right;
background-color: seashell;
}
button {
font-weight: 700;
color: white;
border-radius: 3px;
background: #aac078;
margin-left:10px; margin-top: 10px; margin-bottom: 10px; outline: none;
}
table {
width: 100%;
border-collapse: collapse;
}
td, thead {
padding: 3px;
border: 2px solid #aac078;
text-align: center;
vertical-align:middle;
}
thead {
background: whitesmoke;
}
</style>
</head>
<body>
<div class="body">
<div id="header">
<form action="/test/">
<button type="submit">Новый поиск</button>
</form>
</div>
<g:set var="haveQuery" value="${params.q?.trim()}" />
<g:set var="haveResults" value="${searchResult?.results}" />
<g:if test="${haveResults}">
<div class="list">
<table id="mytable" >
<thead>
<tr>
<td><strong>Звёздность</strong></td>
<td><strong>Название</strong></td>
<td><strong>Страна</strong></td>
</tr>
</thead>
<tbody id="table1">
<g:set var="totalPages" value="${Math.ceil(searchResult.total / searchResult.max)}" />
<g:each in="${searchResult.results}" status="i" var="htls">
<g:if test="${htls.site}">
<tr>
<td>${htls.rating}</td>
<td>${htls.name}<br><a href="${htls.site}" target="_blank" style="font-size: small">Перейти на сайт</a></td>
<td>${htls.country}</td>
</tr>
</g:if>
<g:else>
<tr>
<td>${htls.rating}</td>
<td>${htls.name}</td>
<td>${htls.country}</td>
</tr>
</g:else>
</g:each>
</tbody>
</table>
</div>
<div class="paginateButtons">
<g:paginate params="[q: params.q]" total="${searchResult.total}"/>
</div>
</g:if>
<script>
function sort_rait()
{
var table=$('#mytable');
var tbody =$('#table1');
tbody.find('tr').sort(function(a, b)
{
if($('#rait_order').val()=='desc')
{
return $('td:first', a).text().localeCompare($('td:first', b).text());
}
else
{
return $('td:first', b).text().localeCompare($('td:first', a).text());
}
}).appendTo(tbody);
var sort_order=$('#rait_order').val();
if(sort_order=="asc")
{
document.getElementById("rait_order").value="desc";
}
}
window.addEventListener('load', sort_rait)
</script>
<br/>
<div class="title">
<span>
<g:if test="${haveQuery && haveResults}">
Количество найденных отелей: <strong>${searchResult.total}</strong>
</g:if>
<g:else>
<p style="text-align: center"> Пустой запрос </p>
</g:else>
<g:if test="${haveQuery && !haveResults && !parseException}">
<p style="text-align: center"> По Вашему запросу ничего не найдено </p>
</g:if>
</span>
</div>
<br/>
</div>
</body>
</html> |
|
Скрипт сортировки:
Javascript |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| <script>
function sort_rait()
{
var table=$('#mytable');
var tbody =$('#table1');
tbody.find('tr').sort(function(a, b)
{
if($('#rait_order').val()=='desc')
{
return $('td:first', a).text().localeCompare($('td:first', b).text());
}
else
{
return $('td:first', b).text().localeCompare($('td:first', a).text());
}
}).appendTo(tbody);
var sort_order=$('#rait_order').val();
if(sort_order=="asc")
{
document.getElementById("rait_order").value="desc";
}
}
window.addEventListener('load', sort_rait)
</script> |
|