首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >javascript datatable筛选器不筛选

javascript datatable筛选器不筛选
EN

Stack Overflow用户
提问于 2018-02-28 05:37:03
回答 1查看 63关注 0票数 0

我正在尝试按element.data筛选我的表。我有一个下拉列表,让用户选择的值和提交按钮,一旦他们完成。该表获取初始数据,但是当我选择一个值并单击submit时,我将获得所有值。过滤器根本不起作用。

Javascript过滤器

代码语言:javascript
复制
 $('#Product').on('change', function () {
    var count = 0;
    var value = this.value;

    $('#results-tbody tr').each(function () {

        var element = $(this);

        element.data('filters', element.data('filters').replace(/dropdown/g, ''));

        if (value !== 'All' && element.data("product").indexOf(value) === -1) {
            element.data('filters', element.data('filters') + 'dropdown');
        }
        count = count + hideOrShow(element);
    });
    setResultsCount(count);
});
$('#Changes').on('change', function () {
    var count = 0;
    var value = this.value;
    $('#results-tbody tr').each(function () {

        var element = $(this);

        element.data('filters', element.data('filters').replace(/dropdown/g, ''));

        if (value !== 'All' && element.data("oc").indexOf(value) === -1) {
            element.data('filters', element.data('filters') + 'dropdown');
        }
        count = count + hideOrShow(element);
    });
    setResultsCount(count);
});

报表表页

代码语言:javascript
复制
 var productList = new SelectList(
 new List<SelectListItem>
 {
 new SelectListItem {Text = "Flexitouch", Value = "Flexitouch"},
 new SelectListItem {Text = "ACTitouch", Value = "ACTitouch"},
 new SelectListItem {Text = "Entre", Value = "Entre"},


 }, "Text", "Value");

 var showList = new SelectList(
 new List<SelectListItem>
 {
 new SelectListItem {Text = "Changes Only", Value = "Changes Only"},
 new SelectListItem {Text = "Referrals Only", Value = "Referral Only"},


  }, "Text", "Value");
  <div class="layout clinics">

   @using (Html.BeginForm("AccountSummaryReport", "Reports", 
  FormMethod.Post))
   {
    @Html.ValidationSummary(false)
    <div style="border-bottom:1px solid #bbb">
        <h1>Account Summary Report</h1>
    </div>
    <!--<div class="filter-btns top">
        <h4 class="filter-heading">Quick Search By</h4>
        <input type="button" name="all" class="button1 filter-button active" value="All" />
        <input type="button" name="flexitouch" class="button1 filter-button" value="Flexitouch" />
        <input type="button" name="actitouch" class="button1 filter-button" value="ACTitouch" />
        <input type="button" name="entre" class="button1 filter-button" value="Entre" />
    </div>-->
    <fieldset class="form-wrapper form-side-labels form-labels-125 search-box-center">
        <div class="form-field form-full">
            <!-- New Dropdown ! -->
            <div class="editor-label">
                <label>@Html.DisplayNameFor(model => model.Product)</label>
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(model => model.Product, productList, "All", new { @class = "css-class clinic-dropdown" })
            </div>
        </div>
        <div class="form-field form-full">
            <div class="editor-label">
                <label>@Html.DisplayNameFor(model => model.Changes)</label>
            </div>
            <div class="editor-field">
                @Html.DropDownListFor(model => model.Changes,showList, "All", new { @class = "css-class clinic-dropdown" })
            </div>
        </div>

<div class="form-field">
    <input name="SearchButton" type="submit" value="Search" />
</div>

    </fieldset>

  <table class="table results-table">
            <tr>
                <th><i id="count"> (@ViewBag.Count found) </i></th>
            </tr>
            <tbody id="results-tbody">
                @foreach (var item in Model.SearchResults)
                {
                    <tr class="table__row-link" data-patientname"="@item.PatientLastName , @item.PatientLastName"
                        data-product="@item.Product" data-referral="@item.d_Order_Date" data-oc="@item.d_Order_Complete_Date"
                        data-approved="@item.ApprovedDate" data-inactive="@item.d_Inactive_Date" data-training="@item.LastTrainedDate" data-links="@item.Links" data-filters="none">
                        <td>
                            <a href="@Url.Action("Details", "Patient", new { patientID = item.PT_RecID })">
                                <strong>@Html.DisplayFor(modelItem => item.PatientLastName, item.PatientFirstName) (@Html.DisplayFor(modelItem => item.PT_RecID))</strong>
                                <br />
                                <strong>Product: </strong>@Html.DisplayFor(modelItem => item.Product)
                                <br />
                                <strong>Referral: </strong>@Html.DisplayFor(modelItem => item.d_Order_Date)
                                <br />
                                <strong>OC: </strong> @Html.DisplayFor(modelItem => item.d_Order_Complete_Date)
                                <br />
                                <strong>Shipped: </strong> @Html.DisplayFor(modelItem => item.d_Ship_Date)
                                <br />
                                <strong>Approved: </strong> @Html.DisplayFor(modelItem => item.ApprovedDate)
                                <br />
                                <strong>Inactive: </strong> @Html.DisplayFor(modelItem => item.d_Inactive_Date)
                                <br />
                                <strong>Training: </strong> @Html.DisplayFor(modelItem => item.LastTrainedDate)
                                <br />
                                <strong>Links: </strong> @Html.DisplayFor(modelItem => item.Links)
                                <br />
                            </a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>

模型

代码语言:javascript
复制
public class AccountSummaryReportModel
{ 

    public string Product { get; set; }
    public string Clinic_RecID { get; set; }
    public IEnumerable<v_Report_AccountSummary> SearchResults { get; set; }
    public string SearchButton { get; set; }
    public IEnumerable<SelectListItem> Changes { get; set; }
    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
    [DisplayName("Start")]
    //[DataType(DataType.Date)]
    public DateTime Start { get; set; }
}
EN

回答 1

Stack Overflow用户

发布于 2018-02-28 05:57:42

你有一个事件侦听器"$('#Product').on('change'....",但是我没有看到一个带有id="Product“的控件。我怀疑这就是你的问题。您需要将该id分配给您希望在更改时触发的控件。

我相信你的$('#Changes')事件监听器也有同样的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49018335

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档