diff --git a/src/index.js b/src/index.js index bd8a2f1..23acd23 100644 --- a/src/index.js +++ b/src/index.js @@ -1,92 +1,65 @@ -import React, { useEffect, useRef } from 'react'; +//indexGrpCaptionCond.js import { render } from 'react-dom'; -import { GridComponent, ColumnsDirective, ColumnDirective, Page, Group, Sort, Inject } from '@syncfusion/ej2-react-grids'; -import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-react-popups'; -import axios from 'axios'; import './index.css'; +import React, { useEffect, useRef } from 'react'; +import { + GridComponent, + ColumnsDirective, + ColumnDirective, + Group, + Inject, +} from '@syncfusion/ej2-react-grids'; +import { dataDetails } from './dataGrpCaptionCond'; -const OrderService = { - BASE_URL: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders', - - execute(state) { - return this.getData(state); - }, - - getData(state) { - const { skip, take, sorted } = state; - const pageQuery = `$skip=${skip}&$top=${take}`; - const sortQuery = sorted && sorted.length ? `&$orderby=` + sorted.map(obj => `${obj.name} ${obj.direction}`).join(',') : ''; - const url = `${this.BASE_URL}?${pageQuery}${sortQuery}&$inlinecount=allpages&$format=json`; - - return axios.get(url) - .then(response => { - const data = response.data; - return { result: data['d']['results'], count: parseInt(data['d']['__count'], 10) }; - }) - .catch(error => { - console.error('Error fetching data:', error); - return { result: [], count: 0 }; - }); - } -}; - -const CustomBinding = () => { - const gridRef = useRef(null); - - useEffect(() => { - const state = { skip: 0, take: 150 }; - dataStateChange(state); - }, []); +const OverView = () => { + const grid = useRef(null); - const created = () => { - const spinnerTarget = document.querySelector('#customSpinner'); - createSpinner({ target: spinnerTarget, width: '20px' }); + const groupSettings = { + columns: ['Verified'], }; - const dataStateChange = (state) => { - const spinnerTarget = document.querySelector('#customSpinner'); - - showSpinner(spinnerTarget); // Show the spinner before fetching data + /* +const queryCellInfo = (args) => { + if (args.column.field === 'Verified' && args.cell.classList.contains('e-groupcaption')) { + args.cell.innerHTML = args.data.key === 'true' ? 'Verified' : 'Not Verified'; + } + }; + */ - OrderService.execute(state) - .then(gridData => { - console.log('Data received:', gridData); - gridRef.current.dataSource = gridData; - }) - .catch(error => { - console.error('Error fetching data:', error); - }) - .finally(() => { - hideSpinner(spinnerTarget); // Hide the spinner regardless of success or failure - }); + const queryCellInfo = (args) => { + if (args.column.field === 'Verified' && args.cell.classList.contains('e-groupcaption')) { + const iconClass = args.data.key === 'true' ? 'e-icons e-true' : 'e-icons e-false'; + args.cell.innerHTML = ` ${args.data.key === 'true' ? 'Verified' : 'Not Verified'}`; + } }; return ( -
-
-
- - - - - - - - - -
-
+ + + + + + + + ); }; -render(, document.getElementById('sample')); +render(, document.getElementById('sample')); \ No newline at end of file diff --git a/src/indexGrpCaptionCond.js b/src/indexGrpCaptionCond.js deleted file mode 100644 index 23acd23..0000000 --- a/src/indexGrpCaptionCond.js +++ /dev/null @@ -1,65 +0,0 @@ -//indexGrpCaptionCond.js -import { render } from 'react-dom'; -import './index.css'; -import React, { useEffect, useRef } from 'react'; -import { - GridComponent, - ColumnsDirective, - ColumnDirective, - Group, - Inject, -} from '@syncfusion/ej2-react-grids'; -import { dataDetails } from './dataGrpCaptionCond'; - -const OverView = () => { - const grid = useRef(null); - - const groupSettings = { - columns: ['Verified'], - }; - - /* -const queryCellInfo = (args) => { - if (args.column.field === 'Verified' && args.cell.classList.contains('e-groupcaption')) { - args.cell.innerHTML = args.data.key === 'true' ? 'Verified' : 'Not Verified'; - } - }; - */ - - const queryCellInfo = (args) => { - if (args.column.field === 'Verified' && args.cell.classList.contains('e-groupcaption')) { - const iconClass = args.data.key === 'true' ? 'e-icons e-true' : 'e-icons e-false'; - args.cell.innerHTML = ` ${args.data.key === 'true' ? 'Verified' : 'Not Verified'}`; - } - }; - - return ( - - - - - - - - - ); -}; - -render(, document.getElementById('sample')); \ No newline at end of file diff --git a/src/indexSpinner.js b/src/indexSpinner.js new file mode 100644 index 0000000..b5814ec --- /dev/null +++ b/src/indexSpinner.js @@ -0,0 +1,93 @@ +// indexSpinner.js +import React, { useEffect, useRef } from 'react'; +import { render } from 'react-dom'; +import { GridComponent, ColumnsDirective, ColumnDirective, Page, Group, Sort, Inject } from '@syncfusion/ej2-react-grids'; +import { createSpinner, showSpinner, hideSpinner } from '@syncfusion/ej2-react-popups'; +import axios from 'axios'; +import './index.css'; + +const OrderService = { + BASE_URL: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders', + + execute(state) { + return this.getData(state); + }, + + getData(state) { + const { skip, take, sorted } = state; + const pageQuery = `$skip=${skip}&$top=${take}`; + const sortQuery = sorted && sorted.length ? `&$orderby=` + sorted.map(obj => `${obj.name} ${obj.direction}`).join(',') : ''; + const url = `${this.BASE_URL}?${pageQuery}${sortQuery}&$inlinecount=allpages&$format=json`; + + return axios.get(url) + .then(response => { + const data = response.data; + return { result: data['d']['results'], count: parseInt(data['d']['__count'], 10) }; + }) + .catch(error => { + console.error('Error fetching data:', error); + return { result: [], count: 0 }; + }); + } +}; + +const CustomBinding = () => { + const gridRef = useRef(null); + + useEffect(() => { + const state = { skip: 0, take: 150 }; + dataStateChange(state); + }, []); + + const created = () => { + const spinnerTarget = document.querySelector('#customSpinner'); + createSpinner({ target: spinnerTarget, width: '20px' }); + }; + + const dataStateChange = (state) => { + const spinnerTarget = document.querySelector('#customSpinner'); + + showSpinner(spinnerTarget); // Show the spinner before fetching data + + OrderService.execute(state) + .then(gridData => { + console.log('Data received:', gridData); + gridRef.current.dataSource = gridData; + }) + .catch(error => { + console.error('Error fetching data:', error); + }) + .finally(() => { + hideSpinner(spinnerTarget); // Hide the spinner regardless of success or failure + }); + }; + + return ( +
+
+
+ + + + + + + + + +
+
+ ); +}; + +render(, document.getElementById('sample'));