Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

BaseSearchModel.cs

using Nop.Core.Domain.Common;
using Nop.Core.Infrastructure;

namespace Nop.Web.Framework.Models;

/// 
/// Represents base search model
/// 
public abstract partial record BaseSearchModel : BaseNopModel, IPagingRequestModel
{
    #region Ctor

    protected BaseSearchModel()
    {
        //set the default values
        Length = 10;
    }

    #endregion

    #region Properties

    /// 
    /// Gets a page number
    /// 
    public int Page => (Start / Length) + 1;

    /// 
    /// Gets a page size
    /// 
    public int PageSize => Length;

    /// 
    /// Gets or sets a comma-separated list of available page sizes
    /// 
    public string AvailablePageSizes { get; set; }

    /// 
    /// Gets or sets draw. Draw counter. This is used by DataTables to ensure that the Ajax returns from server-side processing requests are drawn in sequence by DataTables (Ajax requests are asynchronous and thus can return out of sequence).
    /// 
    public string Draw { get; set; }

    /// 
    /// Gets or sets skipping number of rows count. Paging first record indicator.
    /// 
    public int Start { get; set; }

    /// 
    /// Gets or sets paging length. Number of records that the table can display in the current draw. 
    /// 
    public int Length { get; set; }

    #endregion

    #region Methods

    /// 
    /// Set grid page parameters
    /// 
    public void SetGridPageSize()
    {
        var adminAreaSettings = EngineContext.Current.Resolve();
        SetGridPageSize(adminAreaSettings?.DefaultGridPageSize ?? 0, adminAreaSettings?.GridPageSizes);
    }

    /// 
    /// Set popup grid page parameters
    /// 
    public void SetPopupGridPageSize()
    {
        var adminAreaSettings = EngineContext.Current.Resolve();
        SetGridPageSize(adminAreaSettings.PopupGridPageSize, adminAreaSettings.GridPageSizes);
    }

    /// 
    /// Set grid page parameters
    /// 
    /// Page size; pass null to use default value
    /// Available page sizes; pass null to use default value
    public void SetGridPageSize(int pageSize, string availablePageSizes = null)
    {
        Start = 0;
        Length = pageSize;
        AvailablePageSizes = availablePageSizes;
    }

    #endregion
}