Skip to content

Instantly share code, notes, and snippets.

@jaydata
jaydata / jquery-product-editor-10.js
Created September 26, 2016 13:15
Northwind product editor entry point in app.js - initialize OData connection and list product categories
var oProviderConfig = {
name: 'oData',
oDataServiceHost: 'http://localhost:3000/odata'
};
var NorthwindContext = $data('JayStack.NorthwindContext');
var northwind = new NorthwindContext(oProviderConfig);
northwind.onReady(function () {
northwind.Categories.toArray(app.renderCategories);
@jaydata
jaydata / jquery-product-editor-09-index.html
Created September 26, 2016 12:24
Northwind product editor HTML template to render category list
<table id="categoryTable" class="table span3 reset-m" style="margin: 0 10px 10px 0 !important;">
<thead>
<tr>
<th>Category name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
@jaydata
jaydata / jquery-product-editor-08-index.html
Created September 26, 2016 12:10
Include necessary libraries to work with OData endpoint
<head>
<title></title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="lib/jaydata/jaydata.js"></script>
<script src="lib/jaydata/jaydatamodules/deferred.js"></script>
<script src="scripts/Northwind.js"></script>
<script src="scripts/app.js"></script>
</head>
@jaydata
jaydata / jquery-product-editor-07.js
Created September 26, 2016 08:43
Consume OData endpoint using JayData and $data.initService() - dynamic context creation
$data.initService(oProviderConfig.oDataServiceHost)
.then(function (northwind, contextFactory, contexType) {
//you can use your northwind context instace
});
var oProviderConfig = {
name: 'oData',
oDataServiceHost: 'http://localhost:3000/odata'
};
var NorthwindContext = $data('JayStack.NorthwindContext');
var northwind = new NorthwindContext(oProviderConfig);
northwind.onReady(function () {
// work with your data
@jaydata
jaydata / jquery-product-editor-05.js
Last active September 26, 2016 12:06
Generate data model from live OData service using JaySvcUtil node module
//start your own service endpoint from https://github.com/jaystack/odata-v4-northwind-example-service
C:\NorthWindEditor>JaySvcUtil -m http://localhost:3000/odata/$metadata -o northwind.js
@jaydata
jaydata / jquery-product-editor-04.js
Created September 26, 2016 07:03
jQuery product editor - Define data context and its entity sets
$data.EntityContext.extend('NorthwindContext', {
'Products': { type: $data.EntitySet, elementType: NorthwindModel.Product },
'Categories': { type: $data.EntitySet, elementType: NorthwindModel.Category }
});
@jaydata
jaydata / jquery-product-editor-03.js
Last active September 26, 2016 07:20
jQuery product editor - Define Product entity
$data("$data.Entity").extend("Northwind.Product", {
_id: { "type": "Edm.String", "nullable": false, "required": true, "key": true },
Name: { "type": "Edm.String", "nullable": false, "required": true },
CategoryId: { "type": "Edm.String", "nullable": false,"required": true },
QuantityPerUnit: { "type": "Edm.String", "nullable": false, "required": true },
UnitPrice: { "type": "Edm.Decimal", "nullable": false, "required": true },
Discontinued: { "type": "Edm.Boolean", "nullable": false, "required": true }
});
@jaydata
jaydata / 01 retrieve Northwind products - jQuery.js
Last active December 19, 2015 15:19
OData.org blogpost snippets
var queryString = ("/Northwind.svc/Products?"
+ "$filter=((Category/Category_ID eq 1)or"
+ "substringof('tofu',tolower"
+"(Product_Name)))&"
+ "$orderby=Category/Category_Name&"
+ "$select=Product_Name");
$.ajax({
url: queryString,
dataType: 'JSON',
$data.initService('http://yourhost/yourODataService')
.then(function (context) {
// manage your data through context with JSLQ
});