0

我在 div 中有一个 jqGrid orderForm,可以验证用户添加的行数。

我想做的是:每当用户向 jqGrid 添加一行时,该TOTAL_LINE_AMOUNT列中的总数就会加在一起并插入到标签中Subtotal

 $('#orderForm).jqGrid({
        data: details,
        datatype: 'local',
        colNames: ['ID', 'QUANTITY', 'MODEL_ORDER_NUM', 'DESCRIPTION', 'PRICE_EACH', 'TOTAL_LINE_AMOUNT'],
        colModel: [
            { name: 'DETAIL_RECORD_ID', index: 'DETAIL_RECORD_ID', sorttype: 'string' },
            { name: 'QUANTITY', index: 'QUANTITY', sorttype: 'string' },
            { name: 'MODEL_ORDER_NUM', index: 'MODEL_ORDER_NUM', sorttype: 'string' },
            { name: 'DESCRIPTION', index: 'DESCRIPTION', sorttype: 'string' },
            { name: 'PRICE_EACH', index: 'PRICE_EACH', sorttype: 'string' },
            { name: 'TOTAL_LINE_AMOUNT', index: 'TOTAL_LINE_AMOUNT', sorttype: 'string' }
        ],
        search: true,
        onSelectRow: LoadInput,
        loadonce: false,
        jsonReader: { cell: '' },
        sortname: 'DETAIL_RECORD_ID',
        sortorder: 'asc',
        sortable: true,
        ignoreCase: true,
        viewrecords: true,
        height: 'auto',
        width: 'auto',
        shrinkToFit: false,
        hiddengrid: false,
        caption: 'Detail Records'
    });

更新:这是我将数据加载到网格中的方式

Form.Controller.orderForm = new function () {
  var _detailRecordId = 1;
  this.Create = function () {
    var requestData = Controller.GetRequestData();
    requestData.orderForm.push({
        DETAIL_RECORD_ID: "T" + _detailRecordId++,
        REQUEST_RECORD_ID: requestData.REQUEST_RECORD_ID,
        QUANTITY: $('#orderForm_QUANTITY_INPUT').val(),
        MODEL_ORDER_NUM: $('#orderForm_MODEL_ORDER_NUM_INPUT').val(),
        DESCRIPTION: $('#orderForm_DESCRIPTION_INPUT').val(),
        PRICE_EACH: $('#orderForm_PRICE_EACH_INPUT').val(),
        TOTAL_LINE_AMOUNT: $('#orderForm_TOTAL_LINE_AMOUNT_INPUT').text()
    });
    Form.View.orderFrom.LoadGrid(requestData.orderForm);
};
4

1 回答 1

1

您的代码没有显示您在 jqGrid 中使用的编辑机制,因此很难说您应该订阅哪个事件(最有可能它应该是jqGridInlineAfterSaveRowor jqGridAddEditAfterComplete)。

获取列的总和非常简单,因为 jqGrid 有一个现成的方法:

var subTotal = $('#orderForm').jqGrid('getCol', 'TOTAL_LINE_AMOUNT', false, 'sum');

根据您的标签是什么类型的 HTML 元素,您应该能够使用以下之一设置其文本:

$('#Subtotal').text(subTotal);

或者

$('#Subtotal').val(subTotal);
于 2013-08-21T15:09:31.197 回答