//
// inside js script at the top of the page
//

var editTemplateCell = '<a href="javascript:deleteRow(${id});" title="delete">';
    editTemplateCell += '<img style="margin-left:15px;" src="/images/icons/delete.png" alt="delete" /></a>';

var dsResultMenu = new kendo.data.DataSource({
        transport: {
            read: {
                url: "/myurl.php?nocache=" + (new Date()).getTime()
                ,dataType: "json"
                ,data : { id : 10 }
            }
        }
        ,pageSize: 10
        ,group: [ 
            { field: "field1", dir: "asc" }, 
            { field: "field2", dir: "asc" } 
        ]
        ,sort: [
            { field: "field1", dir: "asc" }
        ]
    });
    
 // called from link in the grid, check template
 function  deleteRow(id)
    {
        callHandler(id);
    }
            
    function callHandler(oid)
    {
        $.ajax({
            url: "/deleteItem.php",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: { 'oid' : oid },
            responseType: "json",
            success: onCallHandlerSuccess,
            error: onCallHandlerFail
        });
    }
    
    function onCallHandlerSuccess(result)
    {
        dsResultMenu.read();
        $("#gridResultMenu").data("kendoGrid").refresh();
    }

    function onCallHandlerFail(result)
    {
        alert(result.status + ' ' + result.statusText);
    }
    
    
    $(document).ready(function(){
                
        $("#gridResultMenu").kendoGrid({
            dataSource: dsResultMenu
            ,autoBind: true
            ,height: 400
            ,columns:[
                        
                {
                    field: "id",
                    title: "ID",
                    width : 50,
                    
                },
                {
                    field: "field1",
                    title: "field 1",
                    width : 400
                },
                {
                    field: "field2",
                    title: "field 2"
                },
                {
                    field: "id",
                    title: "DELETE",
                    template : editTemplateCell,
                    width : 60,
                    align:'center'
                }]
            ,scrollable: true
            ,sortable: true
            ,pageable: true
            ,selectable: 'row'  
        });


    });