jqwidgets-scripts-custom
Version:
jQWidgets is an advanced jQuery, Angular 7, Vue, React, ASP .NET MVC, Custom Elements and HTML5 UI framework.
78 lines (68 loc) • 3.18 kB
JavaScript
import React from 'react';
import ReactDOM from 'react-dom';
import JqxGrid from '../../../jqwidgets-react/react_jqxgrid.js';
import JqxButton from '../../../jqwidgets-react/react_jqxbuttons.js';
class App extends React.Component {
componentDidMount() {
this.refs.myButton.on('click', () => {
let gridContent = this.refs.myGrid.exportdata('html');
let newWindow = window.open('', '', 'width=800, height=500'),
document = newWindow.document.open(),
pageContent =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<meta charset="utf-8" />\n' +
'<title>jQWidgets Grid</title>\n' +
'</head>\n' +
'<body>\n' + gridContent + '\n</body>\n</html>';
document.write(pageContent);
document.close();
newWindow.print();
});
}
render() {
let data = generatedata(10);
let source =
{
localdata: data,
datatype: 'array',
datafields:
[
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'available', type: 'bool' },
{ name: 'date', type: 'date' },
{ name: 'quantity', type: 'number' },
{ name: 'price', type: 'number' }
]
};
let dataAdapter = new $.jqx.dataAdapter(source);
let columns =
[
{ text: 'First Name', datafield: 'firstname', width: 120 },
{ text: 'Last Name', datafield: 'lastname', width: 120 },
{ text: 'Product', datafield: 'productname', width: 177 },
{ text: 'Available', datafield: 'available', columntype: 'checkbox', width: 67, cellsalign: 'center', align: 'center' },
{ text: 'Ship Date', datafield: 'date', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'd' },
{ text: 'Quantity', datafield: 'quantity', width: 70, align: 'right', cellsalign: 'right' },
{ text: 'Price', datafield: 'price', cellsalign: 'right', align: 'right', cellsformat: 'c2' }
];
return (
<div style={{ fontSize: 13, fontFamily: 'Verdana', float: 'left' }}>
<JqxGrid ref='myGrid'
width={850} source={dataAdapter} columns={columns}
sortable={true} altrows={true} autoheight={true}
selectionmode={'multiplecellsadvanced'}
/>
<div style={{ marginTop: 20 }}>
<div style={{ marginLeft: 10, float: 'left' }}>
<JqxButton value='Print' ref='myButton' />
</div>
</div>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));