数据表中有关于下拉列表变化的不同数据?需要的想法 [英] Data Table with different data on Change in dropdown ? idea required

查看:66
本文介绍了数据表中有关于下拉列表变化的不同数据?需要的想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

抱歉再次打扰您。



最初我将数据绑定到来自DB的jquery数据表我明白了。



现在我将通过示例展示我所需要的东西。



最初我有一个具有3个列表项的下拉列表国家,州,城市



最初在加载国家时将被选中并且所有数据都将显示到我已经完成的这一点。



现在当用户将他的选择更改为STATES或CITIES时,唯一相应的数据应该绑定到Datattable而不是所有数据?



我不知道如何实现它,但我懒惰的大脑正在考虑创建一个新的数据表甚至可想而知。



我的代码:



Hi
sorry to bother you again .

Well initially i binded the data to jquery datatable from DB where i get it .

Now i will demonstrate my required thing with example .

Initially i have a dropdownlist with 3 list items Countries , states,cities

Initially on load countries will be selected and all data will be displayed TILL THIS POINT I HAVE DONE IT .

Now when user changes his selection to STATES OR CITIES the only respective Data should BIND TO Datattable not all data ?

I have no clue how to achieve it but my lazy brain is thinking to create a new Datatable which is awful even to imagine .

My piece of code :

$(document).ready(function () {

    $("#btnGuru").click(function () {
        tableToExcel('myDataTable', 'W3C Example Table');
    });

    $.datepicker.regional[""].dateFormat = 'dd/mm/yy';
    $.datepicker.setDefaults($.datepicker.regional['']);
    debugger;
    var dt = $('#myDataTable').dataTable({

        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "Home/AjaxHandler",  //Here this gets the complte list . Should i apply some filter on it ? if so how ? AJAXHandler is a action method which gives me complete list
        "bJQueryUI": true,
        "aoColumns": [







我的控制器操作方法代码:






My controller action method code :

public ActionResult AjaxHandler(JQueryDataTableParamModel param)
      {
          var Lead_FullDetails = ser_obj1.Lead_List();
          IEnumerable<LeadsInfoDummy> filteredLeads = Lead_FullDetails;

          //Check whether the companies should be filtered by keyword
          if (!string.IsNullOrEmpty(param.sSearch))
          {
              //Used if particulare columns are filtered
              var ContactNameFilter = Convert.ToString(Request["sSearch_1"]);
              var ContactAddressFilter = Convert.ToString(Request["sSearch_2"]);
              var SourceFilter = Convert.ToString(Request["sSearch_3"]);
              var DomainFilter = Convert.ToString(Request["sSearch_4"]);


              //Optionally check whether the columns are searchable at all

              var isContactNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]);
              var isContactAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
              var isSourceSearchable = Convert.ToBoolean(Request["bSearchable_3"]);
              var isDomainSearchable = Convert.ToBoolean(Request["bSearchable_4"]);


              //filtering rows based on user input

              filteredLeads = Lead_FullDetails.Where(c => isContactNameSearchable && c.Contact_Name.ToLower().Contains(param.sSearch.ToLower())
                           ||
                           isContactAddressSearchable && c.Contact_Address.ToLower().Contains(param.sSearch.ToLower())
                           ||
                           isSourceSearchable && c.Lead_Source.ToLower().Contains(param.sSearch.ToLower())
                           ||
                           isDomainSearchable && c.Domain.ToLower().Contains(param.sSearch.ToLower()));

          }
          else
          {
              filteredLeads = Lead_FullDetails;
          }

          var isContactNameSortable = Convert.ToBoolean(Request["bSortable_1"]);
          var isContactAddressSortable = Convert.ToBoolean(Request["bSortable_2"]);
          var isSourceSortable = Convert.ToBoolean(Request["bSortable_3"]);
          var isDomainSortable = Convert.ToBoolean(Request["bSortable_4"]);
          var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);

          Func<LeadSortModel, string> orderingFunction = (c => sortColumnIndex == 1 && isContactNameSortable ? c.Contact_Name :
                                                        sortColumnIndex == 2 && isContactAddressSortable ? c.Contact_Address :
                                                        sortColumnIndex == 3 && isSourceSortable ? c.Lead_Source :
                                                        sortColumnIndex == 4 && isDomainSortable ? c.Domain :
                                                        "");

          //var sortDirection = Request["sSortDir_0"]; // asc or desc
          //if (sortDirection == "asc")
          //{
          //    filteredLeads = Lead_FullDetails.OrderBy(orderingFunction); // I am unable to do this also due to some error .

          //}
          //else
          //{

          //}

          var DisplayedLeads = filteredLeads.Skip(param.iDisplayStart).Take(param.iDisplayLength);
          var result = from c in DisplayedLeads select new[] { Convert.ToString(c.Lead_Id), c.Contact_Name, c.Contact_Address, c.Lead_Source, c.Domain };
          return Json(new
          {
              sEcho = param.sEcho,
              iTotalRecords = Lead_FullDetails.Count(),
              iTotalDisplayRecords = filteredLeads.Count(),
              aaData = result
          },
                      JsonRequestBehavior.AllowGet);
      }



那么我们怎样才能实现这个目标



我的代码已经是发布在这些链接:

数据表过滤查询?数据贴纸



fnRender在数据表中给出问题? mvc4







关注


So how can we achieve this

My code is already posted in these links :
Data table Filter query ? Datapicker

fnRender giving issue in datatable ? mvc4



Regards

推荐答案

document )。ready( function (){
(document).ready(function () {


#btnGuru)。click( function (){
tableToExcel(' myDataTable'' W3C示例表');
});
("#btnGuru").click(function () { tableToExcel('myDataTable', 'W3C Example Table'); });


.datepicker.regional [ ]。dateFormat = ' dd / mm / yy';
.datepicker.regional[""].dateFormat = 'dd/mm/yy';


这篇关于数据表中有关于下拉列表变化的不同数据?需要的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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