locked
href multiple parameters jquery datatable RRS feed

  • Question

  • User349356202 posted

    Hello,

    I want to know how to pass multiple parameters using jquery datatable. I"m used to only pass 1 value which is the id. But this time, the method that i'm using requires 3 values and one of them should take the value 1.

    <a href=@Url.Action("CheckQuestion", "TestChecking", new { id = i.TestId,order=1,Tid=i.TakerId })>

    This is the jquery datatable code. I want to pass those 3 values id = i.TestId,order=1,Tid=i.TakerId.

    $(document).ready(function () {
    
                $("#employeeTable").DataTable(
                    {                    
                        "ajax": {
                            "url": "/TestChecking/GetAllCopies",
                            "type": "GET",
                            "datatype": "json"
                        },
    
                        "columns": [
    
                            { "data": "TestId" },
                            { "data": "TakenId" },
                            { "data": "TakerId" },
                            {
                                "data": "TakeDate",
                                render: function (data) {
                                    return moment(data).format("DD/MM/YYYY HH:mm:ss");
                                }
                            },
                            {
                                "data": "TakenId", "width": "50px", "render": function (data) {
    
                                    return '<a  title="Check" class="btn btn-success btn-flat" ;" href="/TestChecking/AssignCopies/' + data + '"><span class="glyphicon glyphicon-folder-open" style="vertical-align:initial;"></span></a>';
                                }
    
                            }
                        ]
    
                    });
    
            });

    Thank you.

    Monday, May 28, 2018 10:53 AM

All replies

  • User475983607 posted

    Your question is not clear.  I assume the issue is clicking the link does not invoke the action as expected.  But you have not posted the action or explained what happens and what you expect to happen when clicking the link.  Is there any way you can post the action method?

    Monday, May 28, 2018 11:21 AM
  • User349356202 posted

    Hi,

    This is the method from the controller:

    public ActionResult CheckQuestion(int id, int order, int Tid)
            {
              ......
            }

    As you can see, it has 3 parameters (int id, int order and int Tid).

    If i'm not using a jquery datatable, the code that i'll be using is this:

    <a href=@Url.Action("CheckQuestion", "TestChecking", new { id = i.TestId,order=1,Tid=i.TakerId })>

    When i click on the link it invokes the action.

    However when i'm using a jquery datatable, i don't know how to pass those 3 paremeters.

    Monday, May 28, 2018 11:31 AM
  • User475983607 posted

    Still, the question is not clear.  A jQuery table gets data from an MVC action.  I assume the action uses the input parameters to query the database?  The results are passed to the View and which populates the jQuery table. 

    At this point I can't tell if you have a design issue or you simply need to read the jQuery table documentation.  Can you explain what you are trying to do at a high level?

    Monday, May 28, 2018 11:43 AM
  • User349356202 posted

    The link has the ControllerName/TheMethodName/And the parameters.
    The datatable works fine, it loads all the data. I've tested it. And that's not the issue here.

    I simply want to transform this :

    <a href=@Url.Action("CheckQuestion", "TestChecking", new { id = i.TestId,order=1,Tid=i.TakerId })>

    into jquery code.

    Please look at the datatable's code:

     $(document).ready(function () {
    
                $("#employeeTable").DataTable(
                    {
                        "aoColumnDefs": [{ "bSortable": false, "aTargets": [4] }],
    
                        "ajax": {
                            "url": "/TestChecking/GetAllCopies",
                            "type": "GET",
                            "datatype": "json"
                        },
    
                        "columns": [
    
                            { "data": "TestId" },
                            { "data": "TakenId" },
                            { "data": "TakerId" },
                            {
                                "data": "TakeDate",
                                render: function (data) {
                                    return moment(data).format("DD/MM/YYYY HH:mm:ss");
                                }
                            },
                            {
                                "data": "TakenId", "width": "50px", "render": function (data) {
    
                                    return '<a  title="Check" class="btn btn-success btn-flat" ;" href="/TestChecking/AssignCopies/' + data + '"><span class="glyphicon glyphicon-folder-open" style="vertical-align:initial;"></span></a>';
                                }
    
                            }
                        ]
    
    
    
    
    
                    });

    And this part is for a button that does the action:

                                "data": "TakenId", "width": "50px", "render": function (data) {
    
                                    return '<a  title="Check" class="btn btn-success btn-flat" ;" href="/TestChecking/AssignCopies/' + data + '"><span class="glyphicon glyphicon-folder-open" style="vertical-align:initial;"></span></a>';
                                
    
         

    When you click on the button you engage the link which will be /TestChecking/AssignCopies/TestId 1 TakerId

    The Problem is that "data": "TakenId" is only 1 parameter, i want to use 3. Should i do this: "data": "TakenId" "data2": "1" "data3": "TakerId"???

    href="/TestChecking/AssignCopies/' + data + data2 + data3 +'" !!!!!!!!  That does not work i've already tried that.

    I hope the question is clear now.
    Thanks.

    Monday, May 28, 2018 11:57 AM
  • User36583972 posted


    Hi MedNasser,

    And this part is for a button that does the action:

                                "data": "TakenId", "width": "50px", "render": function (data) {
    
                                    return '<a  title="Check" class="btn btn-success btn-flat" ;" href="/TestChecking/AssignCopies/' + data + '"><span class="glyphicon glyphicon-folder-open" style="vertical-align:initial;"></span></a>';
                                
    
         

    When you click on the button you engage the link which will be /TestChecking/AssignCopies/TestId 1 TakerId

    The Problem is that "data": "TakenId" is only 1 parameter, i want to use 3. Should i do this: "data": "TakenId" "data2": "1" "data3": "TakerId"???

    href="/TestChecking/AssignCopies/' + data + data2 + data3 +'" !!!!!!!!  That does not work i've already tried that.

    May be you can refer the jQuery table columns.render and columns.data documentations.

    I suggest you can go to the JQuery DataTables Forums for getting suitable. Besides, you can subscribe the support service which can ensure that any issues in the software are found and dealt with quickly.

    Best Regards,

    Yong Lu

    Tuesday, May 29, 2018 8:20 AM