【问题标题】:Kendo Grid external filteringKendo Grid 外部过滤
【发布时间】:2018-02-23 00:17:26
【问题描述】:

我已经对我的剑道网格应用了外部过滤器,它可以在单个文本框和一个按钮上正常工作。但是现在我需要在网格上方添加另一个文本框和一个按钮,并根据单击的按钮调用相应的方法。

    //add 2 text boxes and 2 buttons  
    <div style="margin-bottom: 5px;">
    @Html.TextBox("compSearch", (string)TempData["searchString"], new { id = "txtCompanySearch", style = "width: 400px;" })
    <button id="searchButton" class="button" type="button" style="text-align:center;" onclick="searchAccounts()">
        <span>Search</span>
        <img src="~/Content/images/magnifier.png" />
    </button>
    <input type="hidden" id="hdnSrchString" value="@ViewBag.searchString" />

    @Html.TextBox("compSearchByMasterRateSheetId", (string)TempData["searchStringMRS"], new { id = "txtCompanySearchByMasterRateSheetId", style = "width: 400px;" })
    <button id="searchByMasterRateSheetIdButton" class="button" type="button" style="text-align:center;" onclick="searchAccountsMRS()">
        <span>Search By Master Rate Sheet ID</span>
        <img src="~/Content/images/magnifier.png" />
    </button>
    <input type="hidden" id="hdnSrchStringMRS" value="@ViewBag.searchStringMRS" />

</div>

<div class="k-content">



  @(Html.Kendo().Grid<Customer>()
                .Name("accountsGrid")
            .Columns(col =>
            {
                col.Bound(c => c.CustomerName).Title("Account").Width("30%");
                col.Bound(c => c.SourceSystemId).Title("B ID").Width("20%");
                col.Bound(c => c.AccountManager).Title("Account Manager").Width("30%");
                col.Bound(c => c.IsExternalQuotingEnabled).Title("External Quoting Enabled?").Width("20%");
            })
            .SetLevel3Defaults(Model)
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("GetCompanyInfo", "Home").Data("additionalData"))
                .PageSize(20)                  
            )
)

GetCompanyInfo 调用存储的过程和附加数据读取第一个文本框中的文本。

function additionalData() {
        return {
            searchString: $("#txtCompanySearch").val()
        }
    }

所有这些都适用于第一个文本框和按钮单击。单击第二个按钮时,我需要阅读第二个框并调用相应的存储过程来更新存储过程。请指教。

【问题讨论】:

  • 请出示function searchAccounts() {}的javascript。

标签: asp.net asp.net-mvc kendo-ui telerik kendo-grid


【解决方案1】:

对于这种情况,您可以使用由任一点击处理程序设置的全局变量,然后由 additionalData() 使用。

案例 1:两个盒子使用相同的额外数据项

var searchTerm;
function handler1 () { searchTerm = $("#box1").val(); }
function handler2 () { searchTerm = $("#box2").val(); }
function additionalData() { return { searchString: searchTerm } }

案例2:每个盒子需要不同的数据项

var searchData;
function handler1 () { searchData = { searchString:    $("#box1").val()}; }
function handler2 () { searchData = { searchStringMRS: $("#box2").val()}; }
function additionalData() { return searchData; }

您需要将初始 searchTerm 或 searchData 设置为适合初始页面加载。

【讨论】:

    猜你喜欢
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2015-09-21
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多