Вопрос

I try using Rad Grid with web Api as data source

    <telerik:RadGrid runat="server" ID="grdUsers" AllowPaging="true" AllowSorting="true"
        AllowFilteringByColumn="true" PageSize="5">
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" ClientDataKeyNames="Id,PasswordHash">
            <PagerStyle Mode="NumericPages" AlwaysVisible="true" />
            <Columns>
                <telerik:GridImageColumn DataType="System.String" DataImageUrlFields="Image" AlternateText="User image"
                    UniqueName="Image"
                    ImageAlign="Middle" ImageHeight="50px" ImageWidth="50px" AllowFiltering="false" HeaderText="">
                </telerik:GridImageColumn>
                <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name" UniqueName="UserName"
                    DataType="System.String">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FullName" HeaderText="Name" UniqueName="FullName"
                    DataType="System.String">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email"
                    DataType="System.String">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="RegistrationDate" HeaderText="Registration Date" UniqueName="RegistrationDate"
                    DataFormatString="{0:dd/MM/yyyy}">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn UniqueName="btnEdit" ButtonType="PushButton" Text="Edit" CommandName="Edit"></telerik:GridButtonColumn>
                <telerik:GridButtonColumn UniqueName="btnDelete" ButtonCssClass="del" ButtonType="PushButton" Text="Delete" CommandName="Delete"></telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
            <ClientEvents OnCommand="RadGridCommand" />
            <DataBinding Location="/SecuHostapi/Security/User/GetAll" ResponseType="JSON">
                <DataService TableName="SecuHostUser" Type="OData" />
            </DataBinding>
        </ClientSettings>
    </telerik:RadGrid>

Wep Api code

    [HttpGet]
    public List<SecuHostUser> GetAll(ODataQueryOptions<SecuHostUser> options)
    {
        UsersRep userRep = new UsersRep();
        return userRep.GetAll();
     }

although, I have put PageSize="5", the final result show all the data from the data base

Это было полезно?

Решение

This problem can be solved by returning a PageResult instead of a list.

[HttpGet]
public PageResult GetAll(ODataQueryOptions<SecuHostUser> options)
{
    UsersRep userRep = new UsersRep();
    //return userRep.GetAll();

    var users = userRep.GetAll().AsQueryable();
    var results = options.ApplyTo(users);
    return new PageResult<SecuHostUser>(results as IEnumerable<SecuHostUser>,
        Request.GetNextPageLink(), Request.GetInlineCount());
 }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top