Skip to content

DOCINFRA-2341_merged_using_automation #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var tableBody = document.getElementById('datatable').querySelector('tbody');
var tableBody = document.getElementById('datatable')?.querySelector('tbody');
if (!tableBody) {throw new Error('Table body not found');}

var SERVICE_URI = 'https://services.syncfusion.com/js/production/';

Expand All @@ -7,30 +8,61 @@ var dataManager = new ej.data.DataManager({
adaptor: new ej.data.WebApiAdaptor()
});

dataManager.executeQuery(new ej.data.Query()).then(function (e) {
console.log('Original data:', e.result);
const transformed = e.result.map(item => ({
OrderID: item.OrderID,
CustomerID: item.CustomerID.toLowerCase(),
EmployeeID: item.EmployeeID
function applyMiddlewareStack(stack) {
return async function (result) {
let modifiedResult = result;
for (const fn of stack) {
modifiedResult = await fn(modifiedResult);
}
return modifiedResult;
};
}

dataManager.applyPostRequestMiddlewares = applyMiddlewareStack([
async function (result) {
console.log('Original Data:', result);

if (!Array.isArray(result)) {
throw new Error('Expected result to be an array');
}

return result.map(function (item) {
return {
id: item.OrderID,
name: item.CustomerID ? item.CustomerID.toLowerCase() : '',
date: item.OrderDate
? new Date(item.OrderDate).toLocaleDateString()
: 'N/A'
};
});
},

async function (result) {
console.log('Transformed Data:', result);
return result;
}
]);

dataManager.executeQuery(new ej.data.Query())
.then(function (e) {
e.result.forEach(function (data) {
var tr = document.createElement('tr');

var tdId = document.createElement('td');
tdId.textContent = data.id.toString();
tr.appendChild(tdId);

var tdName = document.createElement('td');
tdName.textContent = data.name;
tr.appendChild(tdName);

var tdDate = document.createElement('td');
tdDate.textContent = data.date;
tr.appendChild(tdDate);

tableBody.appendChild(tr);
});
})
);
console.log('Transformed data:', transformed);

transformed.forEach(function(data) {
var tr = document.createElement('tr');
var tdOrder = document.createElement('td');
tdOrder.textContent = data.OrderID;
tr.appendChild(tdOrder);

var tdCustomer = document.createElement('td');
tdCustomer.textContent = data.CustomerID;
tr.appendChild(tdCustomer);

var tdEmployee = document.createElement('td');
tdEmployee.textContent = data.EmployeeID;
tr.appendChild(tdEmployee);

tableBody.appendChild(tr);
});
});
.catch(function (error) {
console.error('❌ Data fetch error:', error);
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { DataManager, Query, WebApiAdaptor, ReturnOption } from '@syncfusion/ej2-data';

const tableBody = document.getElementById('datatable')?.querySelector('tbody');
if (!tableBody) {
throw new Error('Table body not found');
}
if (!tableBody) throw new Error('Table body not found');

const SERVICE_URI = 'https://services.syncfusion.com/js/production/';

Expand All @@ -12,35 +10,57 @@ const dataManager = new DataManager({
adaptor: new WebApiAdaptor()
});

dataManager.executeQuery(new Query()).then((e: ReturnOption) => {
console.log('Original data:', e.result);
function applyMiddlewareStack(stack: ((result: any) => Promise<any>)[]) {
return async function (result: any) {
let modifiedResult = result;
for (const fn of stack) {
modifiedResult = await fn(modifiedResult);
}
return modifiedResult;
};
}

const transformed = (e.result as any[])
.map(item => ({
OrderID: item.OrderID,
CustomerID: item.CustomerID.toLowerCase(),
EmployeeID: item.EmployeeID
}))
dataManager.applyPostRequestMiddlewares = applyMiddlewareStack([
async (result) => {
console.log('Original Data:', result);

console.log('Transformed data:', transformed);
if (!Array.isArray(result)) {
throw new Error('Expected result to be an array');
}

transformed.forEach(data => {
return result.map((item: any) => ({
id: item.OrderID,
name: item.CustomerID?.toLowerCase(),
date: item.OrderDate
? new Date(item.OrderDate).toLocaleDateString()
: 'N/A'
}));
},

async (result) => {
console.log('Transformed Data:', result);
return result;
}
]);

dataManager.executeQuery(new Query()).then((e: ReturnOption) => {
(e.result as any[]).forEach(data => {
const tr = document.createElement('tr');

const tdOrder = document.createElement('td');
tdOrder.textContent = data.OrderID.toString();
tr.appendChild(tdOrder);
const tdId = document.createElement('td');
tdId.textContent = data.id.toString();
tr.appendChild(tdId);

const tdCustomer = document.createElement('td');
tdCustomer.textContent = data.CustomerID;
tr.appendChild(tdCustomer);
const tdName = document.createElement('td');
tdName.textContent = data.name;
tr.appendChild(tdName);

const tdEmployee = document.createElement('td');
tdEmployee.textContent = data.EmployeeID.toString();
tr.appendChild(tdEmployee);
const tdDate = document.createElement('td');
tdDate.textContent = data.date;
tr.appendChild(tdDate);

tableBody.appendChild(tr);
});
}).catch(error => {
console.error('Data fetch error:', error);
console.error('Data fetch error:', error);
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<tr>
<th>Order ID</th>
<th>Customer ID</th>
<th>Employee ID</th>
<th>Date</th>
</tr>
</thead>
<tbody></tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<tr>
<th>Order ID</th>
<th>Customer ID</th>
<th>Employee ID</th>
<th>Date</th>
</tr>
</thead>
<tbody></tbody>
Expand Down
Binary file modified ej2-javascript/data/image/post-request-middleware.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.