0
你好我在我的Asp.Net MVC應用程序中使用JQ網格。在我的網格中有一個名爲InvoiceDate的字段,我必須將它與InvoiceDate進行分組,InvoiceDate隨時間而來,並且在網格中,我必須隨時間顯示日期,但對於分組,我必須將它與僅日期分組即,如果我有3數據JQ網格顯示日期與時間,但只想與日期分組
1. 08/29/2014 13:11:56
2. 08/29/2014 13:12:45
3. 08/30/2014 12:09:20
在網格我有顯示日期與上述相同,但是,分組我必須隻日期組這意味着
2014年8月29日和2014年8月30日,它是可能的,如果是的話請給我解決方案。 我的代碼是
jQuery("#ItemSoldReport").jqGrid({
data: ParsedJson,
datatype: "local",
height: 'auto',
width: 'auto',
rowNum: 100,
rowList: [10, 20, 30, 50, 100],
colNames: ['Date', 'UPC', 'Name', 'Department', 'Qty', 'Cost', 'Price', 'Margin'],
colModel: [
{ name: 'InvoiceDate', index: 'InvoiceDate', width: 90, sorttype: "date", summaryType: 'count', summaryTpl: '({0}) total', resizable: false, formatoptions: { newformat: 'm/d/Y' }, datefmt: "m/d/Y" },
{ name: 'Barcode', index: 'Barcode', width: 130, resizable: false, },
{ name: 'ItemName', index: 'ItemName', width: 150, resizable: false, },
{ name: 'DeptName', index: 'DeptName', width: 120, resizable: false },
{ name: 'ItemQuantity', index: 'ItemQuantity', width: 50, align: "right", sorttype: "int", resizable: false, },
{ name: 'CostPrice', index: 'CostPrice', width: 80, align: "right", sorttype: 'number', formatter: 'number', summaryType: 'sum', resizable: false, },
{ name: 'SalesPrice', index: 'SalesPrice', width: 80, align: "right", sorttype: "number", summaryType: 'sum', formatter: "number", resizable: false, },
{ name: 'ExtendedPriceMargin', index: 'ExtendedPriceMargin', width: 50, align: "right", resizable: false, },
],
pager: "#ItemSoldPager",
viewrecords: true,
sortorder: "desc",
caption: "Item Sold Report",
//sortname: 'DeptName',
grouping: true,
hidegrid: false,
groupingView: {
groupField: ['InvoiceDate'],
groupDataSorted: false,
groupText: ['<b>{0} - {1} Item(s)</b>'],
groupCollapse: true,
groupOrder: ['asc'],
groupSummary: [true],
//groupSorted: false,
},
footerrow: true,
userDataOnFooter: true,
onClickGroup: function (hid, collapsed) {
//saveCollapsedStateToLocalStorage(hid, collapsed)
var i;
i = $.inArray(hid, expandedGroups) > -1;
if (!collapsed && i == false) {
expandedGroups.push(hid);
}
else if (collapsed && i == true) {
//Grouphid.splice(i, 1);
expandedGroups.splice($.inArray(hid, expandedGroups), 1);
}
},
loadComplete: function() {
var $this = $(this),
//sum = $this.jqGrid("getCol", "SalesPrice", false, "sum"),
$footerRow = $(this.grid.sDiv).find("tr.footrow"),
localData = $this.jqGrid("getGridParam", "data"),
totalRows = localData.length,
totalSum = 0,
totalCostSum = 0,
$newFooterRow,
i;
for (i = 0; i < totalRows; i++) {
totalSum += parseFloat(localData[i].SalesPrice, 10);
totalCostSum += parseFloat(localData[i].CostPrice, 10);
}
$footerRow.find(">td[aria-describedby=" + this.id + "_InvoiceDate]")
.text("Grand Total:");
$footerRow.find(">td[aria-describedby=" + this.id + "_SalesPrice]")
.text($.fmatter.util.NumberFormat(totalSum, $.jgrid.formatter.number));
$footerRow.find(">td[aria-describedby=" + this.id + "_CostPrice]")
.text($.fmatter.util.NumberFormat(totalCostSum, $.jgrid.formatter.number));
if (expandedGroups.length > 0) {
for (var i = 0; i <= expandedGroups.length; i++) {
if (typeof (expandedGroups[i]) != "undefined") {
$this.jqGrid("groupingToggle", expandedGroups[i]);
}
}
}
}
});
jQuery("#ItemSoldReport").jqGrid('navGrid', '#ItemSoldPager', { add: false, edit: false, del: false });
jQuery("#ItemSoldReport").setGridWidth("100");
我想在組中應用它,那我該如何應用這個 – 2014-09-01 13:14:50
@AhhijitPandya:你應該在'groupingView'中添加'isInTheSameGroup'和'formatDisplayField'。該代碼將非常接近[demo](http://www.ok-soft-gmbh.com/jqGrid/NotExactGrouping1.htm)數組「isInTheSameGroup」中的第二個函數。確切的實現取決於您擁有的輸入數據的確切格式(您不包含您使用的'ParsedJson'的測試數據)。 – Oleg 2014-09-01 15:23:47