IT/JAVASCRIPT
[JAVASCRIPT] 게시판 List SORT 정렬 처리방법
윤재웅
2019. 12. 6. 09:50
[JAVASCRIPT] 게시판 List SORT 정렬 처리방법
step1
<form name="searchForm" th:action="@{|/list/search|}" method="GET">
<input type="hidden" name="order" th:value="${params.order}" />
<input type="hidden" name="sort" th:value="${params.sort}" />
</form>
<div class="list_sort">
<a href="#name_basic" class="sortable" >제목</a>
<a href="#tag2" class="sortable" >분류</a>
<a href="#creat_place2" class="sortable" >주소</a>
</div>
step2
$('.sortable').on('click', function(event) {
var searchForm = document.forms.searchForm;
var me = $(this);
searchForm.order.value = me.attr('href').replace('#','');
common_setting_sort(searchForm);
searchForm.submit();
});
function common_setting_sort(form){
if(form.sort.value === 'asc'){
form.sort.value = 'desc';
}else{
form.sort.value = 'asc';
}
}
step3
SELECT * FROM TEMP
WHERE TITLE IS NOT NULL
<choose>
<when test='order != null and order != ""'>
ORDER BY ${order} ${sort}
</when>
<otherwise>
ORDER BY BOOK_TITLE
</otherwise>
</choose>