2

Used the data table plugin and try to add the two links Edit and Delete When I click on links it should redirect to some other page.

Please help me on this.. Thanks in advance...

Please find my code snippet:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="@Url.Content("~/Areas/Admin/content/js/bootstrap.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Areas/Admin/content/js/plugins/datatables/jquery.dataTables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Areas/Admin/content/js/plugins/datatables/dataTables.bootstrap.js")" type="text/javascript"></script>
<div class="box-body table-responsive">
            <table id="example1" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>EmployeeID</th>
                        <th>Description</th>
                        <th>Actions</th>
                    </tr>
                </thead>
            </table>
        </div><!-- /.box-body -->
<script>
var serviceRootUrl = 'http://localhost:49425/Services/MyWcfService.svc/';

$(document).ready(function () {

    var oTable = $('#example').dataTable({

        "bJQueryUI": true,
        "bProcessing": true,

        "bServerSide": true,
        "sAjaxSource": serviceRootUrl + "EmployeeListResponseCollection",                
         "aoColumns": [
                    { data: "EmployeeID" },
                    { data: "Description" },
                    {
                        data: null,
                        "sClass": "center",
                        "sDefaultContent": '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
                    }
            ]                


    });

});

1

1 Answer 1

1

Use the mdata and mrender for the additional field or column to the datatables grid. Use this snap code inside the script and it should work.

$(document).ready(function () {
var oTable = $('#example').dataTable({
        "bJQueryUI": true,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": serviceRootUrl + "EmployeeListResponseCollection",                
         "aoColumns": [
                    { "mData": "EmployeeID" },
                    { "mData": "Description" },
                    {
                "mData": "EmployeeID",
                "mRender": function (data, type, full) {
                    return '<a href="' + data + '">Edit</a>';
                }
            },
            {
                "mData": "EmployeeID",
                "mRender": function (data, type, full) {
                    return '<a href="' + data + '">Delete</a>';
                }
            }
            ]
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.