How To Pass Record From Table To Partial View

How To Pass Record From Table To Partial View

Khalid4114Khalid4114 Posts: 3Questions: 2Answers: 0

Hello All ...

Iam trying to pass record from table to partial view but iam not getting the record send it:

i create CountriesTable.js:

var datatable;
$(document).ready(function () {
    loadDataTable();
});

function loadDataTable() {
    datatable = $('#tblData').DataTable({
        "ajax": {
            "url": "/admin/managecountries/GetActiveCountries",
            "type": "GET",
            "datetype": "json"
        },

        columnDefs: [
            {
                targets: [0],
                visible: true,
                searchable: true,
                orderable: true
            },

            {
                targets: [1],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [2],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [3],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [4],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [5],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [6],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [7],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [8],
                visible: false,
                searchable: false,
                orderable: false
            },

            {
                targets: [9],
                visible: true,
                searchable: false,
                orderable: false
            },

        ],

        columns: [

            /*{ "data": "countryID"},*/
            { data: "countryName", "width": "30%" },
            {
                data: "countryStatus", render: function (data, type, row) {
                    if (type === 'display') {
                        if (data == 1) {

                            return `<div class=form-check>` + '<input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="checked-disabled" checked disabled>'; + '</div>'

                        } else {
                            return `<div class=form-check>` + '<input class="form-check-input" type="checkbox" id="inlineCheckbox3" value="checked-disabled" disabled>'; + '</div>'
                        }
                    }
                    return data;
                },
                className: "dt-body-center"
            },
            { data: "countryNotes" },
            { data: "createdBy" },
            { data: "createdDate" },
            { data: "createdDeviceName" },
            { data: "modifiedBy" },
            { data: "modifiedDate" },
            { data: "modifiedDeviceName" },
            {

                data: "countryID",
                render: function (data) {
                    return `<div class="text-center">
                              <a href="/Admin/managecountries/Upsert/${data}" class='btn btn-success text-white' style='cursor:pointer; width:100px;'>
                                <i class='far fa-edit'></i> Edit
                              </a>
                                &nbsp;
                                <a onclick=Delete("/Admin/managecountries/Delete/${data}") class='btn btn-danger text-white' style='cursor:pointer; width:100px;'>
                                <i class='far fa-trash-alt'></i> Delete
                              </a>
                            </div>
                           `;


                }, "width": "30%"
            }
        ],

        displayLength: 5,
        lengthMenu: [[5, 10, 25, 50, 75, 100, -1], [5, 10, 25, 50, 75, 100, 'Show All']],

        language: {
            emptyTable: ' No Records Found !!',
            loadingRecords: 'Loading ...',
            lengthMenu: 'Show _MENU_ Entries',
            zeroRecords: 'No Records Found',
            info: 'Show _START_ To _END_ From The Total List _TOTAL_ ',
            search: 'Search :',
            processing: ' Searching ...',
            infoFiltered: '',
            infoEmpty: 'No Records Found !!',
            paginate: {
                // remove previous & next text from pagination
                first: '&nbsp;' + 'First',
                previous: '&nbsp;' + 'Previous',
                next: '&nbsp;' + 'Next',
                last: '&nbsp;' + 'Last'
            }
        },
        "width": "100%"
    });
}

function Delete(url) {
    swal({
        title: "Are You Sure You Want To Delete?",
        text: "You will not be able to restore that record !",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes Deleted !!!",
        closeOnconfirm: true

    }, function () {

        $.ajax({

            type: 'DELETE',
            url: url,
            success: function (data) {
                if (data.success) {
                    toastr.success(data.message);
                    datatable.ajax.reload();
                }
                else {
                    toastr.error(data.message);
                }

            }
        });

    });
}

now i cannot pass the record when press edit

Any idea ?

Thanks

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Looks like you are creating your own customer edit code. See this example of how to use click events with Datatables. It shows how to get the row data.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It would also be worth looking at Editor - as that'll make those edit operations far easier.

    Colin

Sign In or Register to comment.