Am having issues in retrieving id of the records to perform edit and delete operations.

Am having issues in retrieving id of the records to perform edit and delete operations.

sravan.sriramojusravan.sriramoju Posts: 1Questions: 1Answers: 0

Am having issues in retrieving id of the records to perform edit and delete operations. i loaded data from database and now want to perform edit and delete operation based on the ID. Here is my code. Would be really helpful if anyone could look into my problem. Thanks for any assistance.

<link href="~/Scripts/Lib/DataTables-1.10.4/media/css/jquery.dataTables.css" rel="stylesheet" />



<

script type="text/javascript">
//$(function () {

function format(d) {                
    return '<table cellpadding="5" cellspacing="0" border="1" style="padding-left:50px;">' +
            '<tr>' +
               '<th>Asset Id</th>' +
               '<th>Asset Type</th>' +
               '<th>Address 1</th>' +
               '<th>Quotation Cost</th>' +
               '<th>View</th>' +
               '<th>Action</th>' +
           '</tr>' +
           '<tr">' +
               '<td>' + d.Assets['0'].Asset_Id + '</td>' +
               '<td>' + d.Assets['0'].Asset_Type_Id + '</td>' +
               '<td>' + d.Assets['0'].Address1 + '</td>' +
               '<td>' + d.Assets['0'].RentPerMonth + '</td>' +
               '<td>' + '<a href="" class="Asset_View">Summary</a>' + '</td>' +
               '<td>' + '<a href="" class="Asset_Accept">Accept</a> / <a href="" class="Asset_Reject">Reject</a>' + '</td>' +
        '</tr>' +
        '</table>';
}

// debugger;
var x;

$.ajax({
    url: "/Buyer/BHome/GetCampaignList",
    type: "GET",
    success: function (data) {
        debugger;
        x = data;
        var table = $('#tblcampaign').DataTable({
            "data": JSON.parse(x),
            "columns": [
                {
                    "className": 'details-control',
                    "orderable": false,
                    "data": null,
                    "defaultContent": '',
                },
                    { "data": "Campaigns.CampaignId" },
                    { "data": "Campaigns.CampaignName" },
                    { "data": "Campaigns.StartDate" },
                    { "data": "Campaigns.EndDate" },
                    { "data": "Campaigns.Budget" },
                    { "data": "Campaigns.CampaignStatus" },
                    {
                        data: null,
                        className: "center",
                        defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
                    },
                    {
                        data: null,
                        className: "center",
                        defaultContent: '<a href="" class="editor_view">View</a>'
                    }                      
            ],
            "order": [[1, 'asc']]
        });
        // Add event listener for opening and closing details
        $('#tblcampaign tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row(tr);

            if (row.child.isShown()) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Open this row
                row.child(format(row.data())).show();
                tr.addClass('shown');
            }
        });

        $('#tblcampaign').on('click', 'a.editor_edit', function (e) {
            e.preventDefault();
            alert("true..");
            alert($(this));
            console.log(JSON.stringify($(this)));
            $(location).attr('href', 'http://localhost:4722/Buyer/BHome/EditCampaignList');
            editor
                .title('Edit record')
                .buttons({ "label": "Update", "fn": function () { editor.submit() } })
                .edit($(this).closest('tr'));
        });

        $('#tblcampaign').on('click', 'a.editor_view', function (d) {
            e.preventDefault();
            alert('View function to be implemented..');
        });

        $('#tblcampaign').on('click', 'a.editor_remove', function (e) {
            alert("asfsdf");
            e.preventDefault();
            alert("Delete..");
            editor
                .message('Are you sure you wish to remove this record?')
                .buttons({ "label": "Delete", "fn": function () { editor.submit() } })
                .remove($(this).closest('tr'));
        });
    }
});

</script>

Sno Campaign Name Startdate End date Budget Status Edit / Delete Details
This discussion has been closed.