如何根据下拉列表中选择的值对表进行排序 [英] How to sort a table based on value selected in dropdownlist

查看:127
本文介绍了如何根据下拉列表中选择的值对表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个要求,我必须根据下拉列表中选择的值对html表的内容进行排序。



下拉列表包含2个值:按编号排序和按说明排序。

选择按编号排序时,表格应按编号排序。

在选择排序依据描述时,表格应按说明排序。

我需要使用MVC和jquery。



请帮助我。



谢谢。







@ {

布局= T4MVC.SharedController.ViewNames._Ctx;

}



@ section brandcrambs {



}

@ Html.DropDownList(SortBy,新List< SelectListItem>

{

new SelectListItem {Text =Sort By Number, V alue =0,Selected = true},

new SelectListItem {Text =Sort By Description,Value =1}

})

@ {

var s = @ViewData [currentNode];

}



@ Convert.ToString(s)





@foreach(Model.Nodes中的SubSectionNodesVM n)

{





@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(resultSet中的var项)

{

k ++;

var match = item.Select(m = > m.DefaultValue);



string resultDefaultValue = string.Empty;



if(match!= null )

{

if(match.Count()> 0)

{

resultDefaultValue = match。 ToList()[0];

}

}





< br $>








var i = 0;

foreach(var inneritem in item)

{

k ++;

@if(@ inneritem.RangeStart == null || @ inneritem.RangeStart ==)

{

}
else

{



}

@if(@ inneritem.RangeEnd == null || @ inneritem.RangeEnd ==)

{

}

其他

{

}

}









}



@ resultDefaultValue
@ inneritem.Number 来自:@ inneritem.RangeStart To:@ inneritem.RangeEnd @ inneritem.Description




< script>

$(document).ready(function(){

$ ('#SortBy')。change(function(){

var value = $(#SortBy option:selected)。val();

alert(value );

});

})



< / script>

解决方案

(document).ready(function(){


('#SortBy')。change(function (){

var value =


(#SortBy option:selected)。val();
警报(价值);

});

})



< ; /脚本>

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.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.NumberFrom: @inneritem.RangeStartTo: @inneritem.RangeEnd@inneritem.Description


<script>
$(document).ready(function () {
$('#SortBy').change(function () {
var value = $("#SortBy option:selected").val();
alert(value);
});
})

</script>

解决方案

(document).ready(function () {


('#SortBy').change(function () {
var value =


("#SortBy option:selected").val();
alert(value);
});
})

</script>


这篇关于如何根据下拉列表中选择的值对表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆