Accessing data in a dragged row

Accessing data in a dragged row

TrevTrev Posts: 2Questions: 1Answers: 0

Hi,

What is the best way to access data in a row being dragged?

I have the following code which drags a row from a DataTable to be dropped in a div.

          drawCallback: function () {
            $("#example .draggable_tr").draggable({
              cursor: "move",
              revert: "invalid",
              tolerance: "fit",
              start: function(event, ui){
                $(this).draggable('instance').offset.click = {
                left: 0,
                top: Math.floor(ui.helper.height() / 2)
              }},
              helper: function(){
                var selected = $('tr.selectedRow');
                if (selected.length === 0) {
                  selected = $(this).addClass('selectedRow');
                }
                var container = $("<div\" style=\"background-color:orange; border:1px solid black;width:200px;height:50px\">",
                         "Custom helper</div>").attr('id', 'draggingContainer');
                container.append(selected.clone().removeClass("selectedRow"));
                return container;
              }
              });
          }

Rather than drag the whole row I am trying to define a custom container which will have the same background color as the table row and contain text from one of the cells. Here is a sample object used to populate the table:

{"id":"57","name":"Donna Snider","position":"Customer Support","salary":"$112,000","start_date":"2011/01/25","office":"New York","extn":"4226","color":"#a688df"}

How can I access the name and color fields in order to customise the container?

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    Answer ✓

    Use row().data() to get the row data. Maybe something like this to get the row data:

    var data = table.row( this ).data();
    

    Kevin

  • TrevTrev Posts: 2Questions: 1Answers: 0

    Thanks Kevin

Sign In or Register to comment.