Hi,
I have a requirement where I have to sort the content of a html table based on value selected in dropdown.
The dropdown contain 2 values: Sort by Number and Sort By Description.
On selecting Sort By Number the table should be sorted by Number.
On selecting Sort By Description the table should be sorted by Description.
This I need to do using MVC and jquery.
Please help me out.
Thanks.
@{
Layout = T4MVC.SharedController.ViewNames._Ctx;
}
@section brandcrambs{
@{Html.RenderPartial(T4MVC.SharedController.ViewNames._ProductCatalogBrandCrambs, Model);}
}
@Html.DropDownList("SortBy", new List<SelectListItem>
{
new SelectListItem{ Text="Sort By Number", Value="0", Selected=true},
new SelectListItem{ Text="Sort By Description", Value = "1" }
})
@{
var s = @ViewData["currentNode"];
}
@Convert.ToString(s)
@foreach (SubSectionNodesVM n in Model.Nodes)
{
@if (n.CurrentNode.Key.Contains("Specification"))
{
Html.RenderPartial(T4MVC.SharedController.ViewNames._PrintButtons, n.CurrentNode);
}
var matchValue = n.Nodes as IEnumerable<sitemapnodebase>;
var resultSet = from dtRow in matchValue.AsEnumerable()
group dtRow by dtRow.Prefix into newGroup
orderby newGroup.Key
select newGroup;
var datamodel = resultSet as IEnumerable<sitemapnodebase>;
var k = 0;
@foreach (var item in resultSet)
{
k++;
var match = item.Select(m => m.DefaultValue);
string resultDefaultValue = string.Empty;
if (match != null)
{
if (match.Count() > 0)
{
resultDefaultValue = match.ToList()[0];
}
}
var i = 0;
foreach (var inneritem in item)
{
k++;
@if (@inneritem.RangeStart == null || @inneritem.RangeStart == "")
{
}
else
{
}
@if (@inneritem.RangeEnd == null || @inneritem.RangeEnd == "")
{
}
else
{
}
}
}
@resultDefaultValue |
@inneritem.Number | | From: @inneritem.RangeStart | | To: @inneritem.RangeEnd | @inneritem.Description |
<script>
$(document).ready(function () {
$('#SortBy').change(function () {
var value = $("#SortBy option:selected").val();
alert(value);
});
})
</script>