Javascript 使用模板值将剑道UI网格导出到Excel
我试着跟随,但这对我不起作用。我有:Javascript 使用模板值将剑道UI网格导出到Excel,javascript,excel,kendo-ui,telerik,kendo-grid,Javascript,Excel,Kendo Ui,Telerik,Kendo Grid,我试着跟随,但这对我不起作用。我有: function invoicedJobsGrid() { var invoicedJobsDS = new kendo.data.DataSource({ serverFiltering: true, serverSorting: true, serverPaging: true, pageSize: 25, reques
function invoicedJobsGrid() {
var invoicedJobsDS = new kendo.data.DataSource({
serverFiltering: true,
serverSorting: true,
serverPaging: true,
pageSize: 25,
requestEnd: function (e) {
if (e.type == 'read') {
$('.today-count').html(e.response.counts.today);
$('.week-count').html(e.response.counts.week);
$('.month-count').html(e.response.counts.month);
// document.title = 'Invoiced jobs (' + (e.response.counts.currencies.GBP + e.response.counts.currencies.USD + e.response.counts.currencies.EUR) + ')';
}
},
sort: {
field: "invoice_id",
dir: "desc"
},
transport: {
read: {
url: 'invoiced-list',
dataType: 'json',
type: 'POST'
}
},
error: function (e) {
alert(e.errorThrown + "\n" + e.status + "\n" + e.xhr.responseText);
},
filter: [{
field: 'invoice_date',
operator: 'gte',
value: $('.month-count').parent().data('period')
}],
schema: {
data: "data",
total: 'total',
model: {
id: 'id',
fields: {
invoice_id: {
type: 'number'
},
entity_id: {
type: 'number'
},
job_id: {
type: 'number'
},
invoice_date: {
type: 'date'
},
invoiceDate: {
type: 'date'
},
jobType: {
type: 'number'
},
customer_name: {
type: 'string'
},
termId: {
type: 'number'
},
account_number: {
type: 'string'
},
firstName: {
type: 'string'
},
sales_area_id: {
type: 'number'
},
margin: {
type: 'number'
},
sales_total: {
type: 'number'
},
sales_total_gdp: {
type: 'number'
},
job_costs_value_pounds: {
type: 'number'
},
vat_native: {
type: 'number'
},
buying_parts_value_pounds: {
type: 'number'
},
buying_fees_value_pounds: {
type: 'number'
},
shipping_value_pounds: {
type: 'number'
},
symbol: {
type: 'string'
},
margin_percent: {
type: 'number'
},
zone_name: {
type: 'string'
},
zone_id: {
type: 'number'
},
buying_total: {
type: 'number'
},
emailed_date: {
type: 'date'
}
}
}
},
aggregate: [
{field: "buying_total", aggregate: "sum"},
{field: "buying_total", aggregate: "average"},
{field: "shipping_value_pounds", aggregate: "sum"},
{field: "shipping_value_pounds", aggregate: "average"},
{field: "job_costs_value_pounds", aggregate: "sum"},
{field: "job_costs_value_pounds", aggregate: "average"},
{field: "buying_fees_value_pounds", aggregate: "sum"},
{field: "buying_fees_value_pounds", aggregate: "average"},
{field: "buying_parts_value_pounds", aggregate: "sum"},
{field: "buying_parts_value_pounds", aggregate: "average"},
{field: "sales_total", aggregate: "sum"},
{field: "sales_total", aggregate: "average"},
{field: "margin", aggregate: "sum"},
{field: "margin", aggregate: "average"},
{field: "sales_total_gdp", aggregate: "sum"},
{field: "sales_total_gdp", aggregate: "average"},
{field: "vat_native", aggregate: "sum"},
{field: "vat_native", aggregate: "average"},
]
})
var invoicedJobsGrid = $('#invoicedJobsGrid').kendoGrid({
toolbar: ["excel"],
excel: {
allPages: true
},
excelExport: function(e) {
var sheet = e.workbook.sheets[0];
var template = kendo.template(this.columns[6].template);
for (var i = 1; i < sheet.rows.length; i++) {
var row = sheet.rows[i];
var dataItem = {
zone_name: row.cells[5].value
};
row.cells[5].value = template(dataItem);
console.log(row.cells[5])
}
},
dataSource: invoicedJobsDS,
autoBind: true,
height: 680,
editable: false,
pageable: {
pageSizes: [25, 50, 'All'],
messages: {
display: '{0} - {1} of {2} invoiced jobs',
empty: 'There are no invoiced jobs',
itemsPerPage: 'invoiced jobs per page'
}
},
dataBound: function (e) {
var grid = e.sender;
if (grid.dataSource.total() == 0) {
var colCount = grid.columns.length;
$(e.sender.wrapper)
.find('.k-grid-content tbody')
.append('<tr class="kendo-data-row no-results-row"><td colspan="' + colCount + '" class="no-data">No invoiced jobs for current filters</td></tr>');
}
},
columns: [
{
title: 'Account #',
field: 'accountNumber',
width: '100px',
template: '#=accountNumber ? accountNumber : "<i class=\\"fa fa-pencil create-account-number\\"></i>"#'
},
{
title: 'Customer',
field: 'name',
template: '<a href="/laravel/entity/#=entity_id#" target="_blank">#=name#</a>'
},
{
title: 'Date',
field: 'invoice_date',
width: '85px',
template: '<abbr title="#=kendo.toString(invoice_date, "dd/MM/yyyy at HH:mm")#">#=kendo.toString(invoice_date, "dd/MM/yyyy")#</abbr>'
},
{
title: 'Invoice',
field: 'invoice_id',
width: '80px',
template: '<a href="/laravel/invoice/#=enquiry_id#" target="_blank">#=invoice_id#</a>'
},
{
title: 'Job',
field: 'job_id',
width: '65px',
template: '<a href="/laravel/activity/#=enquiry_id#" target="_blank">#=job_id#</a>'
},
{
title: 'Trdr',
headerTemplate: '<abbr title="Trader">Trdr</abbr>',
field: 'traderId',
width: '90px',
template: '<abbr title="#=full_name#">#=trader#</abbr>',
filterable: {
ui: gridFunctions.traderFilterUI,
extra: false
}
},
{
title: 'Zone',
field: 'zone_id',
filterable: {
ui: gridFunctions.zoneFilterUI,
extra: false
},
width: '120px',
template: '#=zone_name#'
},
{
title: 'Sales (native)',
headerTemplate: 'Sales <small>native</small>',
field: 'sales_total_native',
width: '110px',
template: '#=symbol+kendo.toString(sales_total_native, "n2")#'
},
{
title: 'VAT',
field: 'vat_native',
filterable: false,
sortable: false,
width: '80px',
template: '#=symbol+kendo.toString(vat_native, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
title: 'Total',
field: 'sales_total',
filterable: false,
sortable: false,
width: '100px',
template: '#=symbol+kendo.toString(sales_total, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
title: 'Margin',
field: 'margin',
width: '100px',
template: '<abbr title="#=kendo.toString(margin_percent, "p2")#">#=sales_symbol##=kendo.toString(margin, "n2")#</abbr>',
footerTemplate: '£#: kendo.toString(sum, "n2") #<br /><span class="text-warning">£#: kendo.toString(average, "n2") #</span>'
},
{
title: 'VAT #',
field: 'vatNumber',
width: '110px',
template: '#=vatNumber ? vatNumber : "<i class=\\"fa fa-pencil create-vat-number\\"></i>"#'
},
{
title: 'Total (£)',
field: 'sales_total_gdp',
width: '100px',
template: '<abbr title="Using an exchange rate of: #=rate#">#=sales_symbol##=kendo.toString(sales_total_gdp, "n2")#</abbr>',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
title: 'Term',
field: 'term_id',
width: '90px',
filterable: {
ui: gridFunctions.paymentTermsFilterUI,
extra: false
},
template: '#=term#'
},
{
headerTemplate: 'Buying <small>parts</small>',
field: 'buying_parts_value_pounds',
width: '110px',
template: '#=sales_symbol##=kendo.toString(buying_parts_value_pounds, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
headerTemplate: 'Buying <small>fees</small>',
field: 'buying_fees_value_pounds',
width: '100px',
template: '#=sales_symbol##=kendo.toString(buying_fees_value_pounds, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
headerTemplate: 'Shipping',
field: 'shipping_value_pounds',
width: '90px',
template: '#=sales_symbol##=kendo.toString(shipping_value_pounds, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
headerTemplate: 'Job costs',
field: 'job_costs_value_pounds',
width: '95px',
template: '#=sales_symbol##=kendo.toString(job_costs_value_pounds, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
{
headerTemplate: 'Buying <small>total</small>',
field: 'buying_total',
width: '105px',
template: '#=sales_symbol##=kendo.toString(buying_total, "n2")#',
footerTemplate: '#: kendo.toString(sum, "n2") #<br /><span class="text-warning">#: kendo.toString(average, "n2") #</span>'
},
/*{
headerTemplate: 'Email invoices',
field: 'email_invoices',
filterable: {
ui: gridFunctions.yesNoFilterUI.bind(activeGrid),
extra: false
},
hidden: true,
width: '125px',
template: '#=email_invoices ? "Yes" : "No"#'
},*/
{
headerTemplate: 'Print invoices',
field: 'print_invoices',
filterable: {
ui: gridFunctions.yesNoFilterUI.bind(activeGrid),
extra: false
},
hidden: true,
width: '125px',
template: '#=print_invoices ? "Yes" : "No"#'
},
{
headerTemplate: 'Invoice emailed',
field: 'emailed_date',
hidden: true,
width: '150px',
template: '#=emailed_date ? kendo.toString(emailed_date, "dd/MM/yyyy at HH:mm") : "-"#'
},
{
title: 'ZoneName',
field: 'zone_name',
hidden: true,
template: '#=zone_name#'
},
],
filterable: true,
sortable: true,
scrollable: true
}).data("kendoGrid");
}
函数invoicedJobsGrid(){
var invoicedJobsDS=new kendo.data.DataSource({
是的,
对,,
对,,
页面大小:25,
requestEnd:函数(e){
如果(e.type=='read'){
$('.today count').html(e.response.counts.today);
$('.week count').html(e.response.counts.week);
$('.month count').html(e.response.counts.month);
//document.title='已开具发票的工作(+'(e.response.counts.currences.GBP+e.response.counts.currences.USD+e.response.counts.currences.EUR)+';
}
},
排序:{
字段:“发票id”,
目录:“描述”
},
运输:{
阅读:{
url:“发票列表”,
数据类型:“json”,
类型:“POST”
}
},
错误:函数(e){
警报(e.errorThrown+“\n”+e.status+“\n”+e.xhr.responseText);
},
过滤器:[{
字段:“发票日期”,
操作员:“gte”,
值:$('.month count').parent().data('period'))
}],
模式:{
数据:“数据”,
总计:'总计',
型号:{
id:'id',
字段:{
发票编号:{
键入:“数字”
},
实体id:{
键入:“数字”
},
工作编号:{
键入:“数字”
},
发票日期:{
键入:“日期”
},
发票日期:{
键入:“日期”
},
工作类型:{
键入:“数字”
},
客户名称:{
键入:“字符串”
},
termId:{
键入:“数字”
},
账号:{
键入:“字符串”
},
名字:{
键入:“字符串”
},
销售区域标识:{
键入:“数字”
},
保证金:{
键入:“数字”
},
销售总额:{
键入:“数字”
},
销售总额国内生产总值:{
键入:“数字”
},
工作成本、价值、英镑:{
键入:“数字”
},
本地增值税:{
键入:“数字”
},
购买价值为英镑的零件:{
键入:“数字”
},
购买费用、价值、英镑:{
键入:“数字”
},
装运价值(单位:磅):{
键入:“数字”
},
符号:{
键入:“字符串”
},
利润率(单位百分比):{
键入:“数字”
},
分区名称:{
键入:“字符串”
},
分区id:{
键入:“数字”
},
总购买量:{
键入:“数字”
},
电子邮件发送日期:{
键入:“日期”
}
}
}
},
合计:[
{字段:“购买总额”,合计:“总额”},
{字段:“购买总额”,合计:“平均值”},
{字段:“运输价值”{u磅”,合计:“金额”},
{字段:“运输价值”{u磅”,合计:“平均”},
{字段:“工作成本、价值、英镑”,合计:“总和”},
{字段:“工作成本、价值、英镑”,合计:“平均”},
{字段:“购买费用\价值\英镑”,合计:“金额”},
{字段:“购买费用\价值\英镑”,合计:“平均值”},
{字段:“购买零件”“价值”“英镑”,合计:“总和”},
{字段:“购买零件”“价值”“英镑”,合计:“平均”},
{字段:“销售总额”,合计:“总额”},
{字段:“销售总额”,合计:“平均值”},
{字段:“边距”,合计:“总和”},
{字段:“保证金”,合计:“平均”},
{字段:“销售总额”和“国内生产总值”,合计:“总和”},
{字段:“销售总额”和“gdp”,合计:“平均值”},
{字段:“vat_native”,聚合:“sum”},
{字段:“增值税本地”,聚合:“平均”},
]
})
var invoicedJobsGrid=$(“#invoicedJobsGrid”).kendoGrid({
工具栏:[“excel”],
卓越:{
所有页面:正确
},
Excel导出:函数(e){
var sheet=e.workbook.sheets[0];
var template=kendo.template(此.columns[6].template);
对于(变量i=1;i