Essential JS for Ember
4 Jun 20246 minutes to read
System Requirements
To work with Ember, you need to install the followings on your machine.
-
Node.js 5.x.x+ version.
-
NPM 3.x.x+ version
-
Ember CLI 2.x.x+ version.
-
Any Text Editor
Create a simple Ember Application
Please follow the below steps to use Syncfusion Ember add-on in your Ember CLI application.
-
Create Ember CLI application using the command ember new ember-app.
-
Add syncfusion-ember in
package.json
to add the Syncfusion Ember add-on into your applicationember-app
. -
Add syncfusion-javascript package for source files (
scripts
andcss
).
"devDependencies": {
...
"syncfusion-ember":"*"; //To install the latest version
"syncfusion-javascript": "*"; // To install source files
}
- Disable
EXTEND_PROTOTYPES
option in theenvironment.js
file underconfig
folder to preventon
function prototype extension in our controls events.
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: false
},
-
Open the command prompt in the root folder and run the command
npm install
to download the dependent files in node-modules. -
Copy the files
ej.web.all.min
andjsrender.min
fromweb/scripts
folder which is in JavaScript build samples location(Click Explore Demos button from the Javascript Dashboard)
or copyej.web.all.min
fromnode_modules/syncfusion-javascript/Scripts/ej/web
and downloadjsrender.min
file from CDN into thevendor
folder. Import the same into the application using below code inember-cli-build.js
.
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
// Add options here
});
app.import('vendor/ej.web.all.min.js');
app.import('vendor/jsrender.min.js');
return app.toTree();
};
-
Create the folder
scripts
andcontent
in public folder and copy JavaScript and CSS files fromweb/scripts
andweb/themes
folder which is in JavaScript build samples location(Click Explore Demos button from the Javascript Dashboard)
or copy thethemes
files fromnode_modules/syncfusion-javascript/Content/ej/web
into created folders. -
And include the necessary file references in Index page which is in
app
folder of the Ember application.
<head>
<link rel="stylesheet" href="{{rootURL}}
content/ejthemes/default-theme/ej.web.all.min.css">
</head>
<body>
<script src="{{rootURL}}scripts/scripts/jsondata.min.js" type="text/javascript"></script>
</body>
Create Grid sample in the Ember CLI application
-
Open the command prompt in the folder
ember-app
. -
Use the command ember generate route grid/default to create template
default.hbs
file in templates folder and routerdefault.js
file in routes folder. It also add the routing content inrouter.js
. -
Use below code in
default.hbs
in templates folder to render the Grid.
<div class="e-control">
{{ej-grid id="Grid" e-dataSource=model.data e-columns=model.cols e-allowPaging=true }}
</div>
- Use the below code in
default.js
in routes folder to bind the model to the Grid.
export default Ember.Route.extend({
model() {
return {
data: window.gridData,
cols: [
{ field: "OrderID", headerText: "Order ID", width: 75, textAlign: ej.TextAlign.Right },
{ field: "CustomerID", headerText: "Customer ID", width: 80 },
{ field: "EmployeeID", headerText: "Employee ID", width: 75, textAlign: ej.TextAlign.Right},
{ field: "Freight", width: 75, format: "{0:C}", textAlign: ej.TextAlign.Right, priority: 3 },
{ field: "OrderDate", headerText: "Order Date", format: "{0:MM/dd/yyyy}"},
{ field: "ShipCity", headerText: "Ship City", width: 110, priority: 2 }
]
}
}
});
- Use the below code in
.eslintrc
file to ignore the ESLint errors while usingej
in samples as likeej.TextAlign.Right
.
...
rules: {
...
},
globals: {
ej: false
}
...
Build or Run the Ember CLI application
-
To Build the Ember CLI application using the command
ember build
which builds the application and creates thedist
folder. Now you can host thedist
folder in IIS. -
To Run the Ember CLI application using the command
ember serve
which builds the application and creates thedist
folder. However it hosts the application in the urlhttp://localhost:4200
. -
Open the browser and navigates to
http://localhost:4200
.