const country = [
{name: 'United States', countryId: '1'},
{name: 'Australia', countryId: '2'},
{name: 'India', countryId: '3'}
];
const gridWiersze = new Grid({
dataSource: window.orderData,
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: 'Normal',
newRowPosition: 'Bottom'
},
toolbar: ['Add', 'Delete', 'Edit', 'Update', 'Cancel'],
toolbarClick: gridWierszeToolbarClickHandler.bind(this),
columns: [
{
field: 'wierszId',
isPrimaryKey: true,
visible: false
},
{
field: 'ilosc',
headerText: 'Ilość',
textAlign: 'Right',
validationRules: {required: true, number: true}, width: 140
},
{
field: 'rysunek',
headerText: 'Rysunek',
width: 120,
template: '#wierszeRysunekTemplate',
editType: 'dropdownedit',
edit: {
params: {
query: new Query(),
dataSource: country,
fields: {value: 'countryId', text: 'name'},
allowFiltering: true
}
}
},
<script id="wierszeRysunekTemplate" type="text/x-template">
<a rel='nofollow' href="#">${rysunek}</a>
</script>
|
ej.base.enableRipple(true);
var grid = new ej.grids.Grid({
dataSource: window.orderDatas,
columns: [
{
field: 'OrderID', width: 120, headerText: 'Order ID', isPrimaryKey: true, textAlign: 'Right',
validationRules: { required: true, number: true }
},
{
field: 'CustomerID', foreignKeyField: 'CustomerID', foreignKeyValue: 'ContactName', dataSource: window.customerData,
width: 150, headerText: 'Customer Name', validationRules: { required: true }
},
]
}
);
grid.appendTo('#Grid'); |
|
var grid = new ej.grids.Grid({
dataSource: window.hierarchyOrderdata,
columns: [
{
...
field: 'EmployeeID', foreignKeyField: 'EmployeeID', foreignKeyValue: 'FirstName', dataSource: window.employeeData, template: '#template',
width: 150, headerText: 'Customer Name', validationRules: { required: true }
},
] |
|
<script id="template" type="text/x-template">
<div class="image">
<a>${customHelper(data)}</a>
</div>
</script>
<script>
<script>
function customHelper(args) {
var str;
var gridObj = document.getElementById('Grid')['ej2_instances'][0]; // created grid instance
// get a foreign-key value
if(args[gridObj.getForeignKeyColumns()[0].field]===args.foreignKeyData[gridObj.getForeignKeyColumns()[0].field]){
str=args.foreignKeyData[gridObj.getForeignKeyColumns()[0].foreignKeyValue];
}
return str;
}
</script> |