jQuery Grid Validation

In order to have validation when editing is enabled into the grid you need to use validator function of the datasource’s fields. Also each field have nullable property which can be set to true (its default value) or false. When the field cannot be nullable and we pass null the error event is triggered. For example into the following grdi declaration if we pass null to the ProductName or 0 as value of the ProductID the error event will be thrown.

$("#grid1").shieldGrid({
dataSource: {
    data: products,
    schema: {
        fields: {
            id: {
                path: "ProductID", type: Number, validator: function (value) {
                    if (value == 0) { return undefined; } else { return value; }
                }
            },
            name: { path: "ProductName", type: String, nullable: false },
            quantity: { path: "SupplierID", type: Number },
            price: { path: "UnitPrice", type: Number },
            units: { path: "UnitsInStock", type: Number },
            discontinued: { path: "Discontinued", type: Boolean },
            myDate: { path: "d", type: Date }
        }
    }
},
events: 
    {
        error: function (e) {
             var path = e.path;
             var value = e.value;
             var editor = editor;

// Perform action
        },
        editorCreating: function(e) {
            if (e.field == "price") {
                e.options = { max: 50 };
            }
        }
    },
rowHover: false,
columns: [
    { field: "id" },
    { field: "name", width: "200px" },
    { field: "quantity" },
    { field: "price" },
    { field: "units" },
    { field: "discontinued" },
        { field: "myDate", format: "{0:MM/dd/yyyy}" }
],
editing: {
    enabled: true,
    event: "doubleclick", // "click" default (when batch or incell editing is used)
    type: "cell", // "cell"
    mode: "inline", // "form", "popup"
}
});