我希望能够在读取(刷新)后从我的Kendo网格中推送记录计数。
这是我的剑道网格:
@(Html.Kendo().Grid(Model)
.Name("SearchWindowGrid")
.Columns(columns =>
{
columns.Bound(p => p.SYSTEM_ITEMS_SEGMENT1).Hidden();
})
.ClientRowTemplate(
"<tr>" +
"<td>" +
"<span><b>#: SYSTEM_ITEMS_SEGMENT1#</b></span> <br/>" +
"<span>#: DESCRIPTION# </span>" +
"</td>" +
"</tr>"
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("PopulateSearchWindow", "Item").Data("additionalSearchWindowInfo"))
.Events(ev => ev.Error("onErrorSearchWindow"))
)
.Selectable(s => s.Enabled(true).Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.Scrollable(s => s.Enabled(true).Height(450))
)
我的操作系统操作:
public ActionResult PopulateSearchWindow([DataSourceRequest] DataSourceRequest request, string option, string searchText, string searchDesc)
{
try
{
var derps= _idg.SearchItems(searchText, searchDesc, _adg.OrganizationCode).ToList();
return Json(derps.ToDataSourceResult(request, ModelState));
}
catch (Exception e)
{
ModelState.AddModelError("ExceptionErrors", e.Message);
return Json(new List<Derp>().ToDataSourceResult(request, ModelState));
}
}
这是强制数据刷新的功能:
function refreshData(){
$("#SearchWindowGrid").data("kendoGrid").dataSource.read();
//TODO: get the total count and push to #countElement
var count = $("#SearchWindowGrid").data("kendoGrid").length; //not sure what to do here
$("#countElement").val(count);
}
我把我的TODO放在jQuery函数中我希望能够获得行数并将该数字推送到我页面上的特定元素中。
答案 0 :(得分:34)
根据API参考here
dataSource有一个total()函数。所以你应该能够在理论上做到以下几点:
function refreshData(){
var grid = $("#SearchWindowGrid").data("kendoGrid");
grid.dataSource.read();
var count = grid.dataSource.total();
$("#countElement").val(count);
}
答案 1 :(得分:11)
我发现当你在.read()函数之后请求.total()时,即使你在read函数之后调用.refresh(),网格也不会真正刷新。通过定义更改事件,以下内容可以使总体更加优雅和准确:
@(Html.Kendo().Grid(Model)
.Name("SearchWindowGrid")
...
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("PopulateSearchWindow", "Item").Data("additionalSearchWindowInfo"))
.Events(ev => ev.Error("onErrorSearchWindow").Change("OnGridChange"))
)
)
使用以下脚本:
function refreshData(){
var grid = $("#SearchWindowGrid").data("kendoGrid");
grid.dataSource.read();
grid.refresh();
}
function OnGridChange() {
var grid = $("#SearchWindowGrid").data("kendoGrid");
var count = grid.dataSource.total();
$("#countElement").val(count);
}
答案 2 :(得分:0)
gardarvalur 代码也可以正常运行:
$status =Input::get('CallStatus');
$alternate_phone =Input::get('alt_phone');
if (! empty($alternate_phone) && ! empty($status)) {
if ($status != "completed" || $status != "queued") {
/* start the next call */
$account_sid = ...;
$auth_token = ...;
$client = new \Services_Twilio($account_sid, $auth_token);
try {
$client->account->calls->create('+448008021203', '+'.$alt_phone, 'http://xyz/order_msg.html', array(
'Method' => 'GET',
"StatusCallback" => "http://xyz/phone_events,
"StatusCallbackMethod" => "GET",
"StatusCallbackEvent" => array("completed"),
'Record' => 'false',
));
} catch (\Exception $e) {
$log->error('Phone Events Error: ' . $e);
}
}
}