Click here to Skip to main content
15,896,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an jquery grid and want to delete, edit from grid.
My question is how get the selected row ID


<script type="text/javascript">
        $(document).ready(function () {            

            $("#Jgrid").jqGrid({
                caption: "SubCatagory",
                url: '/api/SubCatagory/GetAllSubcatagoryGrid',
                datatype: "json",
                mtype: 'GET',
                contentType: "application/json; charset-utf-8",
                colNames: ['SubCatagory ID', 'SubCatagory Name', 'SubCatagory Code', 'CatagoryId'],
                colModel: [
                            { key: true, hidden: true, name: 'SubCatagoryId', index: 'SubCatagoryId', editable: true },
                            { key: false, name: 'SubCatagoryName', index: 'SubCatagoryName', editable: true },
                            { key: false, name: 'SubCatagoryCode', index: 'SubCatagoryCode', editable: true },
                            { key: false, name: 'CatagoryId', index: 'CatagoryId', editable: true }

                ],
                pager: jQuery('#pager'),
                rowNum: 10,
                rowList: [10, 20, 30, 40],
                height: '100%',
                viewrecords: true,
                caption: 'SubCatagory List',
                emptyrecords: 'No records to display',
                jsonReader: {
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records",
                    repeatitems: false,
                    Id: "0"
                }
            }).navGrid('#pager', { edit: true, add: true, del: true, search: false, refresh: true },
            {
                // edit options
                zIndex: 100,
                url: '/api/SubCatagory/EditSubCatagoryId/',
                closeOnEscape: true,
                closeAfterEdit: true,
                recreateForm: true,
                afterComplete: function (response) {
                    if (response.responseText) {
                        alert(response.responseText);
                    }
                }
            },
        {
            // add options
            zIndex: 100,
            url: "/api/SubCatagory/AddSubCatagoryId/",
            closeOnEscape: true,
            closeAfterAdd: true,
            afterComplete: function (response) {
                if (response.responseText) {
                    alert(response.responseText);
                }
            }
        },
        
        {
            // delete options
            
            zIndex: 100,
            url: "/api/SubCatagory/DeleteSubCatagoryId/", // I want selected Id here using + sign
            datatype: "json",
            mtype: 'Delete',
            contentType: "application/json; charset-utf-8",
            closeOnEscape: true,
            closeAfterDelete: true,
            recreateForm: true,
            msg: "Are you sure you want to delete this task?",
            afterComplete: function (response) {
                if (response.responseText) {
                    alert(response.responseText);
                }
            }
        });

        });
</script>


XML
<table id="Jgrid"></table>
            <div id="pager"></div>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900