gpt4 book ai didi

javascript - 将 Id 传递给 Jqgrid 的子网格

转载 作者:行者123 更新时间:2023-11-28 07:56:21 24 4
gpt4 key购买 nike

在这里,我将使用 InvoiceId 扩展子网格,但我不知道如何获取 InvoiceId 并将其传递给子网格 url。我的主网格有 InvoiceId。这是 JqGrid。当我将发票 ID 硬编码到子网格时url 然后它就可以工作了。

 <script type="text/javascript">
$(function () {

$('#jqgrid').jqGrid({

url: 'Sales/GetAllSalesOrders/',

datatype: 'json',
mtype: 'GET',
//columns names
colNames: ['InvoiceId', 'CustomerId', 'SubTotal', 'TotalDiscount', 'VAT', 'NBT', 'Amount', 'Balance'],
//columns model
colModel: [
{ name: 'InvoiceId', index: 'InvoiceId' },
{ name: 'CustomerId', index: 'CustomerId',align:'center' },
{ name: 'SubTotal', index: 'SubTotal', align: 'right' },
{ name: 'FullDiscount', index: 'FullDiscount', align: 'right' },
{ name: 'Vat', index: 'Vat', align: 'right' },
{ name: 'Nbt', index: 'Nbt', align: 'right' },
//{ name: 'Total', index: 'Total', align: 'left' },
{ name: 'NetAmount', index: 'NetAmount', align: 'right' },
{ name: 'Balance', index: 'Balance', align: 'right' }
],

pager: '#jqgrid',
rowNum: 10,
sortname: 'InvoiceId',
sortorder: 'asc',
viewrecords: true,
width: 'auto',
height: 'auto',
gridview: true,
rowNum: 50,
rowTotal: 200,
rowList: [20, 30, 50, 100],
rownumbers: false,
rownumWidth: 40,
loadonce: true,
subGrid: true,
subgridtype: "json",
//subrid model
subGridModel: [{
//subgrid columns names
// name: ['InvoiceItemId', 'Quantity', 'Rate', 'DiscountAmount', 'Amount'],
name: ['InvoiceItemId', 'Quantity','Amount'],
width: [100, 100,100],
align: ['left', 'right','right'],

//postData: { id: 22 }
}],
//url from which subgrid data should be requested
subGridUrl: '/Sales/GetSalesItemsByInvoiceId/'

});

我的 Controller 接受 ID,

 [HttpGet]
public JsonResult GetSalesItemsByInvoiceId(int InvoiceId)
{
//Some code here
}

最佳答案

您可以使用subGridBeforeExpand设置新值 subGridUrl :$(this).jqGrid("setGridParam", {subGridUrl: newValue}); .

或者您可以考虑使用subGridRowExpanded实现grid as subgrid 。网格作为子网格允许您最大程度地控制子网格的内容。 jqGrid 只是创建空 <div>对于在扩展行下添加的附加行的右侧部分。一需空位<table>子网格内部,可选 <div>对于寻呼机。之后,只需创建新的网格即可。 url grdi 的 URL 是子网格的 URL。我看到你使用 loadonce: true在主网格中。也许您可以在加载主网格期间直接下载每个网格的完整子网格。 The answer提供了此类实现的示例。

关于javascript - 将 Id 传递给 Jqgrid 的子网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26030429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com