首页 新闻 会员 周边 捐助

使用easyui-datagrid读取数据的问题(datatable转json)

0
悬赏园豆:10 [已关闭问题] 关闭于 2013-11-01 09:53

前端使用datagrid显示数据

<table id="@(prefix)-datagrid" class="easyui-datagrid"
        data-options="singleSelect:true,idField:'Id',rownumbers:true,fit:true,fitColumns:true,pagination:true,pageSize:10,pagePosition:'bottom',url:'@Url.Action("RunStatList",new { Model.Id })'">
    <thead>
        <tr>
            @{
                var index = 0;
                foreach (DataColumn column in Model.Columns)
                {
                    if (column.ColumnName.Contains("Id") || column.ColumnName.Contains("ID") || column.ColumnName.Contains("id"))
                    {
                        continue;
                    }
                    if (index == 0)
                    {
                <th data-options="field:'@Html.Encode(column.ColumnName)',width:80">@Html.Encode(column.ColumnName)</th>
                    }
                    else
                    {
                        var column1 = column;
                        var item = Model.Links.FirstOrDefault(x => x.Text == column1.ColumnName);
                        if (item != null && item.Value.EndsWith("&chart"))
                        {
                <th data-options="field:'@Html.Encode(column.ColumnName)',width:80"><a href="#" class="showchart" index="@index">@Html.Encode(column.ColumnName)</a></th>
                        }
                        else
                        {
                <th data-options="field:'@Html.Encode(column.ColumnName)',width:80">@Html.Encode(column.ColumnName)</th>
                        }
                    }
                    index++;
                }
            }
        </tr>
    </thead>
    <tbody>
        @{
            const string regexReplace = @"@\w+";
            const string regexTarget = @"(?<=target=).+";
            foreach (DataRow row in Model)
            {
            <tr>
                @foreach (DataColumn column in Model.Columns)
                {
                    if (column.ColumnName.Contains("Id") || column.ColumnName.Contains("ID") || column.ColumnName.Contains("id"))
                    {
                        continue;
                    }
                    var column1 = column;
                    var item = Model.Links.FirstOrDefault(x => x.Text == column1.ColumnName);
                    if (item != null && !string.IsNullOrEmpty(item.Value))
                    {
                        if (item.Value.Equals("&chart"))
                        {
                    <td>@Html.Encode(row[column.ColumnName])</td>
                        }
                        else
                        {
                            var link = item.Value;
                            if (link.Equals("&chart"))
                            {
                    <td>@Html.Encode(row[column.ColumnName])</td>
                                continue;
                            }
                            if (Regex.IsMatch(link, regexReplace))
                            {
                                var replace = Regex.Match(link, regexReplace).Value;
                                link = Regex.Replace(link, replace, row[replace.Substring(1)].ToString());
                            }
                            link = link.Replace("@queryKey", ViewData["StatId"].ToString());
                            var target = Regex.Match(link, regexTarget).Value;
                    <td><a href="@link" rel="@target" target="@target">@Html.Encode(row[column.ColumnName])</a></td>
                        }
                    }
                    else
                    {
                    <td>@Html.Encode(row[column.ColumnName])</td>
                    }
                }

            </tr>

            }
        }
    </tbody>
</table


在前端可以显示数据,但使用分页的时候就不正常了,点击下一页后,数据还是显示第一页的。用firebug查看HTML数据却有相应。

后台请求操作:

public ActionResult RunStatList(Guid id, int page = 1)
        {
            return BaseReadFramework(
                () =>
                {
                    var queryModel = new RunStatModel { Id = id, Page = page };
                    List<SelfStatQueryCondition> conditions = GetConditions();
                    SelfStatQuery query = SelfStatQuery.TryFind(queryModel.Id);
                    var queryConditions = query.Conditions;
                    foreach (var condition in queryConditions)
                    {
                        var item = conditions.FirstOrDefault(c => c.Name.Equals(condition.Name));
                        if (item == null) continue;
                        condition.Value = item.Value;
                    }
                    return RunStateResult(query, queryModel.Format().Query(query, queryConditions));
                });
        }

怎样才能正常换页?需要将datatable转换成json吗?

sidecore的主页 sidecore | 初学一级 | 园豆:2
提问于:2013-07-07 22:04
< >
分享
所有回答(1)
0

你确定点击下一页的时候,提交给后台的page是对的吗

Yu | 园豆:12990 (专家六级) | 2013-07-08 10:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册