現在、ページングに問題があるグリッドに取り組んでいます。グリッドは、15 個の項目が含まれるポイントまでいっぱいになります。これはページ サイズの最大値ですが、それを超えるページは追加されません。ページが追加されない理由がよくわかりません。以下は私のコードです。
意見
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);
}
どんな助けでも大歓迎です。皆さんありがとう。
敬具、 チャド・ジョンソン