1
我正在研究當前與尋呼有關的問題。網格填充到它有15個項目的地步。這是最大頁面大小,但是,頁面不會被添加。我不完全確定它爲什麼不添加頁面。以下是我的代碼。尋呼無法在我的Telerik Grid中工作
查看
var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
<table class="adminContent">
<tr>
<td>
@(Html.Telerik().Grid<CategoryModel.CategoryUnitsModel>()
.Name("categoryunits-grid")
.DataKeys(keys =>
{
keys.Add(x => x.Id);
keys.Add(x => x.CategoryId);
keys.Add(x => x.UnitId);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax()
.Select("CategoryUnitsList", "Category", new { categoryId = Model.Id })
.Insert("CategoryUnitsInsert", "Category", new { categoryId = Model.Id })
.Update("CategoryUnitsInsert", "Category", new { categoryId = Model.Id })
.Delete("CategoryUnitsDelete", "Category", new { categoryId = Model.Id });
})
.Columns(columns =>
{
columns.Bound(x => x.UnitId)
.Visible(false);
columns.Bound(x => x.UnitText);
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
})
.Width(100);
})
.ToolBar(commands => commands.Insert())
.Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
.ClientEvents(events => events.OnEdit("onEdit"))
.EnableCustomBinding(true))
<script type="text/javascript">
function onRowDataBound(e) {
$(e.row).find('a.t-grid-edit').remove(); //remove Delete button
}
function onEdit(e) {
$.getJSON('@Url.Action("LoadAvailableUnits", "Category")', { categoryId: $("#Id").val() }, function (data) {
var ddl = $("#UnitText").data("tDropDownList");
if (data.length > 0) {
ddl.dataBind(data);
ddl.reload();
}
else {
$('a[class="t-button t-grid-cancel"]').click();
alert("There are no Units left to select from");
}
});
}
</script>
</td>
</tr>
</table>
EditorTemplates \ CategoryUnit
@using Telerik.Web.Mvc.UI;
@Html.Telerik().DropDownList().Name("UnitText")
模型(CategoryModel.CategoryUnitsModel)
public partial class CategoryUnitsModel : BaseNopEntityModel
{
public int CategoryId { get; set; }
public int UnitId { get; set; }
[NopResourceDisplayName("Admin.Catalog.Categories.Units.Fields.UnitText")]
[UIHint("CategoryUnit")]
public string UnitText { get; set; }
}
控制器
[HttpPost, GridAction(EnableCustomBinding = true)]
public ActionResult CategoryUnitsList(GridCommand command, int categoryId)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var categoryUnits = _unitsService.GetCategoryUnits(categoryId, command.Page - 1, command.PageSize);
var categoryUnitsModel = PrepareCategoryUnitsModel(categoryUnits);
var model = new GridModel<CategoryModel.CategoryUnitsModel>
{
Data = categoryUnitsModel,
Total = categoryUnitsModel.Count
};
return new JsonResult
{
Data = model
};
}
public JsonResult LoadAvailableUnits(int categoryId)
{
var categoryUnits = _unitsService.GetAvailableUnits(categoryId);
var categoryUnitsModel = PrepareAvailableUnitsInModel(categoryUnits);
var returnData = new SelectList(categoryUnitsModel, "UnitId", "UnitText");
return Json(returnData, JsonRequestBehavior.AllowGet);
}
[GridAction(EnableCustomBinding = true)]
public ActionResult CategoryUnitsInsert(GridCommand command, CategoryModel.CategoryUnitsModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var searchForEntry = _unitsService.GetCategoryUnitByCategoryIdAndUnitId(model.CategoryId, Int32.Parse(model.UnitText));
if (searchForEntry != null)
{
return CategoryUnitsList(command, model.CategoryId);
}
var categoryUnit = new CategoryUnits
{
UnitId = Int32.Parse(model.UnitText),
CategoryId = model.CategoryId
};
_unitsService.InsertCategoryUnit(categoryUnit);
return CategoryUnitsList(command, model.CategoryId);
}
[GridAction(EnableCustomBinding = true)]
public ActionResult CategoryUnitsDelete(GridCommand command, CategoryModel.CategoryUnitsModel model, int id)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var categoryId = model.CategoryId;
_unitsService.DeleteCategoryUnit(model.CategoryId, id);
return CategoryUnitsList(command, categoryId);
}
任何幫助將不勝感激。謝謝大家。
最親切的問候, 乍得約翰遜
我也有這個問題。你能解釋一下嗎? – SRI
當然可以。發生了什麼事(我記得)是當我打電話給Entity時,我會收到一個項目清單。然後,我會將我的數據庫模型合併到頁面的UI模型中。不同之處在於我的UI模型與數據庫模型中的數據不同,因爲我沒有使用我從數據庫模型獲得的總數。我開始將總數從數據庫模型傳遞到UI模型,這解決了我的問題。希望這可以幫助。 – IyaTaisho