如何填补jq​​Grid的数据文件头 [英] How to fill document header from jqgrid data

查看:97
本文介绍了如何填补jq​​Grid的数据文件头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP .NET MVC2页包含订单表头数据(订单号,客户,订单数据等):

 <形式ID ='_形式类='表单字段的行动=''的onsubmit =SaveDocument();返回false;'>
<输入ID =数字NAME =数字/><选择一个id ='PaymentTerm的名字='PaymentTerm'>
<期权价值=''>< /选项><期权价值='0'>现金和LT; /选项>
<期权价值='10'>10天< /选项>
< /选择>< /表及GT;

和秩序行presented在jqGrid的。

我正在寻找一种方法来控制像JSON日期填写订单headcer数据
像jqGrid的填充数据。
为了尽量减少请求也许最好是在jqGrid的数据请求返回头数据。
对于这种附加参数documentId被传递到控制器。

的GetData返回文件头中的文档对象名称值对。
如何分配这些值来形成的jqGrid loadcomplete或其他地方的浏览器元素?

 公共JsonResult的GetData(INT页,诠释行,字符串过滤器,
          INT documentId){
    变种查询= ...;
    变种总记录= query.Count();    VAR documentHeader =新的FormCollection();
    //在生产code的值是从数据库中读取:
    documentHeader.Add(编号,123); //表单包含输入类型=文本名称=数字元素
    documentHeader.Add(PaymentTerm,10); //表单包含选择name ='PaymentTerm元素
    ...    返回JSON(新{
        总=页面+ 1,
        页=页,
        文件= documentHeader,
        行=(从查询项
                选择 {
                    ID = item.Id.ToString(),
                    电池=新[] {
                        item.Product code,
                        item.ProductName,
                        item.Quantity,
                        item.Price
                    }
                 })。了ToList()
    },
    JsonRequestBehavior.AllowGet);
}


解决方案

如果我理解正确你的问题,你可以使用 beforeProcessing loadComplete 回调填补基于来自服务器的响应的形式的数据。第一个数据这两个回调( beforeProcessing loadComplete 参数)将包含的从服务器的返回的所有数据。所以,你有机会获得数据 文件属性,它有相同的格式在服务器上。

我不知道你为什么使用文件类型的FormCollection 的。在我看来,最本土使用匿名类型的数据:

返回JSON(新{
    总=页面+ 1,
    页=页,
    文件= {新
        数= 123,
        paymentTerm = 10
    },
    行=(...)
},
JsonRequestBehavior.AllowGet);

文件的确切类型恐怕不是那么重要了。

beforeProcessing loadComplete 你可以使用数据的相应属性。文档相同的格式。例如:

beforeProcessing:功能(数据){
    VAR hearderData = data.document;
    如果(hearderData){
        如果(hearderData.number){
            $(#号)VAL(hearderData.number)。
        }
        如果(hearderData.paymentTerm){
            $(#PaymentTerm)VAL(hearderData.paymentTerm)。
        }
    }
}

ASP .NET MVC2 page contains order header data (order number, customer, order data etc):

<form id='_form' class='form-fields' action='' onsubmit='SaveDocument();return false;'>
<input id='Number' name='Number' />

<select id='PaymentTerm' name='PaymentTerm'>
<option value=''></option><option value='0'>Cash</option>
<option value='10'>10 days</option>
</select>

</form>

and order rows presented in jqgrid.

I'm looking for a way to fill order headcer data from json date from controller like like jqgrid fills data. To minimize request maybe it is best to return header data in jqgrid data request. For this additional parameter documentId is passed to controller.

GetData returns document header as name value pairs in document object. How to assign those values to form elements in browser in jqgrid loadcomplete or other place ?

public JsonResult GetData(int page, int rows, string filters,
          int documentId )

{
    var query = ...;
    var totalRecords = query.Count();

    var documentHeader = new FormCollection();
    // In production code those values are read from database:
    documentHeader.Add("Number", 123);  // form contains input type='text' name='Number' element
    documentHeader.Add("PaymentTerm", "10"); // form contains select name='PaymentTerm' element
    ...

    return Json(new {
        total = page+1,
        page=page,
        document = documentHeader,
        rows = (from item in query
                select {
                    id = item.Id.ToString(),
                    cell = new[] {
                        item.ProductCode,
                        item.ProductName,
                        item.Quantity,
                        item.Price
                    }
                 }).ToList()
    },
    JsonRequestBehavior.AllowGet);
}

解决方案

If I understand correct your question you can use beforeProcessing or loadComplete callbacks to fill the form data based on the response from the server. The first data parameter of both callbacks (beforeProcessing or loadComplete) will contains all the data returned from the server. So you have access to document property of data and it has the same format as on the server.

I am not sure why you use document of the type FormCollection. It seems to me the most native to use anonymous type of data:

return Json(new {
    total = page + 1,
    page = page,
    document = new {
        number = 123,
        paymentTerm = 10
    },
    rows = (...)
},
JsonRequestBehavior.AllowGet);

but the exact type of document is probably not so important.

Inside of beforeProcessing or loadComplete you can just use the corresponding properties of data.document in the same format. For example

beforeProcessing: function (data) {
    var hearderData = data.document;
    if (hearderData) {
        if (hearderData.number) {
            $("#Number").val(hearderData.number);
        }
        if (hearderData.paymentTerm) {
            $("#PaymentTerm").val(hearderData.paymentTerm);
        }
    }
}

这篇关于如何填补jq​​Grid的数据文件头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆