1

"render": function(d, t, r) {
    $("#timeSlots option").each(function(e){
        var v = $(this).val();
        var $option = $("<option></option>", {
            "text": v,
            "value": v,
        });
        if(d === v){
            $option.attr("selected", "selected")
        };
    }); 
} 

|
  • 1

1

3

$("#timeSlots option").each(function(e) {
  times.push($(this).val());
})

var times = [

];

$("#timeSlots option").each(function(e) {
  times.push($(this).val());
})

$(function() {
  $("#example").DataTable({
    "columns": [
      null,
      {
        "render": function(d, t, r) {
          var $select = $("<select></select>", {
            "id": r[0] + "start",
            "value": d
          });
          $.each(times, function(k, v) {
            var $option = $("<option></option>", {
              "text": v,
              "value": v
            });
            if (d === v) {
              $option.attr("selected", "selected")
            }
            $select.append($option);
          });
          return $select.prop("outerHTML");
        }
      },
      {
        "render": function(d, t, r) {
          var $select = $("<select></select>", {
            "id": r[0] + "start",
            "value": d
          });
          $.each(times, function(k, v) {
            var $option = $("<option></option>", {
              "text": v,
              "value": v
            });
            if (d === v) {
              $option.attr("selected", "selected")
            }
            $select.append($option);
          });
          return $select.prop("outerHTML");
        }
      }
    ]
  });
});

|