jQuery Grid Cancel User Iteraction

In many cases when the user perform some action over the grid line sorting, selection, editing etc. you may want to cancel the action if some condition is not executed. In this case you can use the command event and to cancel the action. For example if you want the prevent selection you can use following code snippet:

$("#grid").shieldGrid({
    dataSource: {
        data: [
            { ID: 1, name: "name1" },
            { ID: 2, name: "name2" }
        ]
    },
    columns: [
        { field: "ID" },
        { field: "name" }
    ],
    events: {
        command: function (e) {
        if (e.commandName == "selectionChanged") {
            var toBeSelected = e.toBeSelected;  //- array with all elements which will be selected
            e.cancel = true;
        }
    }
});