|
| 1 | +--- |
| 2 | +title: Create a Sample Application with Kendo UI for jQuery and Vite |
| 3 | +page_title: Create a Sample Application with Vite | Kendo UI for jQuery |
| 4 | +description: "A guide on how to set up a project with Vite and Kendo UI for jQuery." |
| 5 | +slug: getting_started_vite |
| 6 | +position: 10 |
| 7 | +--- |
| 8 | + |
| 9 | +# Getting Started with Kendo UI for jQuery and Vite |
| 10 | + |
| 11 | +This guide provides the steps for creating a sample application with [Vite](https://vitejs.dev/) and Kendo UI for jQuery. |
| 12 | + |
| 13 | +After completing this guide, you will have a basic Vite application that includes a Kendo UI for jQuery Grid component with minimal configuration and local data. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +* [Node.js](https://nodejs.org/) installed on your machine. The [recommended versions](https://vite.dev/guide/#scaffolding-your-first-vite-project) are `20.19+` or `22.12+`. |
| 18 | +* A preferred text editor or IDE. |
| 19 | + |
| 20 | +## 1. Create a Vite Project |
| 21 | + |
| 22 | +First, create a new Vite project. You can use the following command to set up a vanilla JavaScript project: |
| 23 | + |
| 24 | +```sh |
| 25 | +npm create vite@latest my-kendo-app -- --template vanilla |
| 26 | +``` |
| 27 | + |
| 28 | +Then, navigate to the project directory: |
| 29 | + |
| 30 | +```sh |
| 31 | +cd my-kendo-app |
| 32 | +``` |
| 33 | + |
| 34 | +## 2. Install Kendo UI for jQuery and Dependencies |
| 35 | + |
| 36 | +Install the Kendo UI for jQuery NPM package and its peer dependency, jQuery: |
| 37 | + |
| 38 | +```sh |
| 39 | +npm install --save @progress/kendo-ui jquery |
| 40 | +``` |
| 41 | + |
| 42 | +## 3. Install the Kendo UI Theme |
| 43 | + |
| 44 | +```sh |
| 45 | +npm install @progress/kendo-theme-classic --save |
| 46 | +``` |
| 47 | + |
| 48 | +For more information about the Kendo Themes, refer to the dedicated Themes installation [article](https://www.telerik.com/design-system/docs/themes/get-started/installation/). |
| 49 | + |
| 50 | +## 4. Ensure jQuery is Globally Accessible |
| 51 | + |
| 52 | +The Kendo scripts expect that the `jQuery` variable is available in the global scope. |
| 53 | + |
| 54 | +In the `src` folder, add a `globals.js` file and export jQuery globally: |
| 55 | + |
| 56 | +```javascript |
| 57 | +import jQuery from 'jquery'; |
| 58 | +window.$ = window.jQuery = jQuery; |
| 59 | + |
| 60 | +export default jQuery; |
| 61 | +``` |
| 62 | + |
| 63 | +## 5. Add the HTML Markup |
| 64 | + |
| 65 | +Open `index.html` and add a `<div>` element that will be used to initialize the Grid component: |
| 66 | + |
| 67 | +```html |
| 68 | +<body> |
| 69 | + <div id="app"> |
| 70 | + <h3>Grid</h3> |
| 71 | + <div id="grid"></div> |
| 72 | + </div> |
| 73 | + <script type="module" src="/src/main.js"></script> |
| 74 | +</body> |
| 75 | +``` |
| 76 | + |
| 77 | +## 6. Import the Scripts |
| 78 | + |
| 79 | +Import jQuery and the Kendo UI scripts you need in the `main.js` file. For this guide, you'll import the Grid component and its dependencies: |
| 80 | + |
| 81 | +```javascript |
| 82 | +import './globals.js'; // Ensure jQuery is accessible in the global scope. |
| 83 | +import '@progress/kendo-theme-classic/dist/all.css'; // Either import the needed theme here or add it in the index.html. |
| 84 | +// Import only the required Kendo modules. |
| 85 | +import '@progress/kendo-ui/esm/kendo.core.js'; |
| 86 | +import '@progress/kendo-ui/esm/kendo.data.js'; |
| 87 | +import '@progress/kendo-ui/esm/kendo.grid.js'; |
| 88 | +``` |
| 89 | + |
| 90 | +## 7. Initialize the Grid |
| 91 | + |
| 92 | +In the `main.js` file, initialize the Grid and add its configuration: |
| 93 | + |
| 94 | +```javascript |
| 95 | +$(document).ready(() => { |
| 96 | + $("#grid").kendoGrid({ |
| 97 | + dataSource: { |
| 98 | + data: [ |
| 99 | + { name: "Jane Doe", age: 30 }, |
| 100 | + { name: "John Smith", age: 33 } |
| 101 | + ], |
| 102 | + schema: { |
| 103 | + model: { |
| 104 | + fields: { |
| 105 | + name: { type: "string" }, |
| 106 | + age: { type: "number" } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + }, |
| 111 | + columns: [ |
| 112 | + { field: "name", title: "Name" }, |
| 113 | + { field: "age", title: "Age" } |
| 114 | + ] |
| 115 | + }); |
| 116 | +}); |
| 117 | +``` |
| 118 | + |
| 119 | +## 8. Build and Run the Application |
| 120 | + |
| 121 | +Execute the following command to build and run the app: |
| 122 | + |
| 123 | +```sh |
| 124 | +npm run dev |
| 125 | +``` |
| 126 | + |
| 127 | +## See Also |
| 128 | + |
| 129 | +* [Installing with NPM]({% slug kendoui_npm_packages_kendoui_installation %}) |
| 130 | +* [Module Bundlers]({% slug module_bundlers_integration_kendoui %}) |
| 131 | +* [Licensing Overview]({% licensing-overview %}) |
0 commit comments