Reputation: 240
I have applied external filtering to my kendo grid which works fine with a single textbox and a button. But now I need to add another text box and a button above the grid and based on the button clicked, call the respective method.
//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 calls the stored proc and additionalData reads the text in the 1st text box.
function additionalData() {
return {
searchString: $("#txtCompanySearch").val()
}
}
All this works for the 1st text box and button click. I need to read the 2nd box when the 2nd button is clicked and call the respective stored proc to update the stored proc. Please advise.
Upvotes: 0
Views: 894
Reputation: 27508
For this scenario you can use a global variable that is set by either of the click handlers, and then used by additionalData().
Case 1: both boxes uses same extra data item
var searchTerm;
function handler1 () { searchTerm = $("#box1").val(); }
function handler2 () { searchTerm = $("#box2").val(); }
function additionalData() { return { searchString: searchTerm } }
Case 2: each box requires a different data item
var searchData;
function handler1 () { searchData = { searchString: $("#box1").val()}; }
function handler2 () { searchData = { searchStringMRS: $("#box2").val()}; }
function additionalData() { return searchData; }
You will need to set the initial searchTerm or searchData to be appropriate for the initial page load.
Upvotes: 1