0

I have a datatable populated with aaData which is depicting the task created by users. Now, there is an action column in datatable which has two or three action buttons or logos like pdf - to view the user guide of that task, browse- link for the source code of the task and one is contributors logo which onclick should display the contributors for that particular task.

The aaData is of the following format which is populating the table

"aaData": [
    [
        "JSAG Home Page",
        "JSAG Home page contains information about various POCs done",
        "05/12/2012",
        [
                {
                   "displayValue":"Browse",
                   "link":"http://myTask.com/home",
                   "displayIcon" : "browselogo"
                },
                {   
                    "displayValue":"Source Code",
                    "link":"svn/HomePage/trunk/",
                    "displayIcon" : "svnlogo"
                },
                {   
                   "displayValue":"Audience Overview",
                    "link":"svn/Documents/Audience Overview.pdf",
                    "displayIcon" : "pdflogo"
               },
                 {  
                    "displayValue":"Contributors: ABC,XYZ",
                    "link":"#",
                    "displayIcon" : "people"
             }

        ],

    ],
    [
        "Backlog",
        "Backlog Forum application is designed to provide a platform for different groups to maintain backlog task items. ",
        "25/08/2012",
        [
            {   
                "displayValue":"Browse",
                "link":"http://mytask.com/BacklogApp",
                "displayIcon" : "browselogo"
            },
            {   
            "displayValue":"Source Code",
                "link":"svn/trunk/webapp-project/",
                "displayIcon" : "svnlogo"
            },
            {   
            "displayValue":"Contributors: ABC",
                "link":"#",
                "displayIcon" : "people"
            }
        ],

    ]
  ]

This format is for all datatables and contributors logo is there in all. What i wanted was, when user clicks the contributors icon, he should be able to see those contributors "ABC, XYZ, PQR".

I thought of fetching the action column data and then $each() the contributors array but i am not able to proceed with it.

How can i achieve this thing? How can i pick up the column value onclick because each datatable is being populated dynamically. Please help.

Below is the code to populate a contributors div

$(document).on('click', '#contributor', function(contributors){
        $.each(contributors, function(i, data) {
            var ul_data = "<li><h3>"+ data+ "</h3></li>";
            $("#contributors_div").append(ul_data);
        });
   }
    $('#contributors_div').show();
   });

How do i getrecentActdata as my contributors JSON array

1 Answer 1

1

Its going to be similar to this, provided you are declaring you datatable in the variable oTable

$(document).on('click', '#contributor', function(){
      var aPos = oTable.fnGetPosition( $(this) );
      console.log(aPos);
      //if aPos returns an array in console, use first val at pos zero to get row data
      var aData = oTable.fnGetData(aPos[0]);
      console.log(aData);
      // inspect your returned object, then tailor your $.each iteration
            $.each( aData["contributors"], function(i, data) {
                var ul_data = "<li><h3>"+ data+ "</h3></li>";
                $("#contributors_div").append(ul_data);
            });
       }
        $('#contributors_div').show();
       });
Sign up to request clarification or add additional context in comments.

5 Comments

thats the point no. How am i going to get that datatable on an icon click?
actually, the JSON format has been modified. Could you please update your code accordingly. I just need to pick "displayValue":"Contributors: ABC,XYZ",. I have oTable data as well
also with this code i am getting error Uncaught TypeError: Cannot call method 'toUpperCase' of undefined in jquery.datatables.js file
Can you post your datatables initialization? Also what do the console.logs show?
Well thnx Jay. This answer was somewhat helpful and i figured out the solution.

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.