Thanks for help before. I'll appreciate it ;)
I've been googling to answer this problem but I didn't find the right answer yet.
I've been trying to filter my results (records) by using dropdown as the filter and using jquery in ASP MVC (Just in my case).
(Urutkan berdasarkan means Filter by. And Terbaru means Newest.)
The dropdown enables you to sort the content by Date, Popular, and Alphabet. How can I filter it by jquery with dropdown?
Here's the view:
<div class="col s12 m12 l12 hide-on-small-only hide-on-med-only" style="border-bottom: 2px solid #9e9e9e;">
<div class="col l9">
<span class="inline">
<span class="left-align grey-text text-darken-3 left" style="font-size: 1.7rem;">Artikel Medis</span>
<span class="right-align right" style="margin-top: 15px;">
<label class="black-text">Urutkan Berdasarkan:</label>
</span>
</span>
</div>
<div class="input-field col l3 right left-align select-web-news" style="margin-bottom: 0;">
@Html.DropDownList("FilterDropdown")
</div>
</div>
<div class="col s12 m12 l12 left">
<ul class="ul-news" id="target">
@foreach (var item in Model.ArticleClient)
{
@Html.Partial("~/Views/Shared/_News.cshtml", item)
}
</ul>
<div class="pager">
@Html.Pager(Model.ArticleClient.PageSize, Model.ArticleClient.PageNumber, Model.ArticleClient.TotalItemCount)
</div>
</div>
And the jquery:
<script type="text/javascript">
$(document).ready(function () {
$("#FilterDropdown").change(function () {
var filterSelected = $("select option:selected").first().text();
$.get('@Url.Action("~/Views/Shared/_News.cshtml")', { id: newsFilter }, function (data) {
$("#target").html.data;
});
});
});
</script>
can anyone help me to solve and for sorting this with jquery or javascript?
fell free for using fiddle.
If the view in my ASP MVC is not understandable. Let's pretending the view would be like this:
<select>
<option value="0">Sort by Name</option>
<option value="1">Sort by Date</option>
<option value="2">Sort by Popular</option>
</select>
<ul class="listitems">
<li data-position="1">
<div class="name">Item 1</div>
<div class="date">11/01/2000</div>
<div class="popular">2</div>
</li>
<li data-position="2">
<div class="name">Item 2</div>
<div class="date">11/01/2001</div>
<div class="popular">3</div>
</li>
<li data-position="3">
<div class="name">Item 3</div>
<div class="date">11/01/2002</div>
<div class="popular">4</div>
</li>
<li data-position="4">
<div class="name">Item 4</div>
<div class="date">11/01/2003</div>
<div class="popular">5</div>
</li>
</ul>
Oia, if my ASP MVC code is not appropriate, feel free to give me the suggestion ;) Thanks for guidance :)