Add data to datatable when the checkbox is selected using Json in MVC












0















I want to add data to a datatable when the checkbox of the first table is selected. at the moment when i clicked checkbox1 on the first table the data added to second table but my problem is when i select checkbox2 the data refresh in the the second table and showed the data related to the value of checkbox2. I want the table to show the data from both checkbox as showed by the image below. thanks



enter image description here



Datatable1



 $(document).ready(function () {
var table = $('#tblBulckTicket').DataTable({
"pageLength": 5
});
});


Datatable2



   // call child ticket
$("#tblBulckTicket").on('change', "input[type='checkbox']", function (e) {
tchildticket();

});


//Child ticket
var enabletemplateListVM;
function tchildticket() {
var pticket = $('#tblBulckTicket').find('input[type=checkbox]:checked').val();
enabletemplateListVM = {
dt: null,
init: function () {
dt = $('#childtable').DataTable({
"pageLength": 10,
"serverSide": false,
"destroy": true,
"ordering": true,
"searching": false,
"LengthChange": false,
"Filter": false,
"paging": true,
"language": {
processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> '
},
"order": [[0, "desc"]],
"ajax": {
@*"url": "/Home/GetChildTickets1?id="+@ViewBag.id,*@
"url": "/Db/GetChildTickets?id="+pticket,
"type": "POST",
"datatype": "json",
"dataSrc": function (d) {
return d
}
},

"columns": [

{
"target":"0",
"data": "Id",
//"autoWidth": true,
"render": function (data, type, full) {
if (type === 'display') {
var attrDisabled = '';

// If ticket is closed
if (full['CurrentStatus'] === 'Closed') {
// Disable the checkbox
attrDisabled = 'disabled';
}
data = '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '" ' + attrDisabled + '/>';
}
return data;
}
},
{
"title": "Ticket Id", "data": "Id", "name": "Id", "autoWidth": true,
"render": function (data, type, row, meta) {
if (type === 'display') {
data = '<a class="pull-left btn btn-primary btn-xs" href="/Home/Ticket/?id=' + data + '"> <i class="fas fa-hashtag"></i>' + data + ' </a > ';
}
return data;
}
},
{
"title": "Logged On", "data": "CreatedOn", "name": "CreatedOn",
render: function (data, type, full, meta) {
if (data !== null) {
return (moment(data).format("DD/MM/YYYY"));
} else {
return '';
}
}
},
{ "title": "Ticket Type", "data": "TypeofWork", "name": "TypeofWork" },
{ "title": "Subject", "data": "Subject", "name": "Subject" },
{ "title": "Contact", "data": "ContactId", "name": "ContactId" },
{ "title": "Status ", "data": "CurrentStatus", "name": "CurrentStatus" },
{ "title": "Team", "data": "Teamid", "name": "Teamid" },
],

});
}
}
enabletemplateListVM.init();









share|improve this question





























    0















    I want to add data to a datatable when the checkbox of the first table is selected. at the moment when i clicked checkbox1 on the first table the data added to second table but my problem is when i select checkbox2 the data refresh in the the second table and showed the data related to the value of checkbox2. I want the table to show the data from both checkbox as showed by the image below. thanks



    enter image description here



    Datatable1



     $(document).ready(function () {
    var table = $('#tblBulckTicket').DataTable({
    "pageLength": 5
    });
    });


    Datatable2



       // call child ticket
    $("#tblBulckTicket").on('change', "input[type='checkbox']", function (e) {
    tchildticket();

    });


    //Child ticket
    var enabletemplateListVM;
    function tchildticket() {
    var pticket = $('#tblBulckTicket').find('input[type=checkbox]:checked').val();
    enabletemplateListVM = {
    dt: null,
    init: function () {
    dt = $('#childtable').DataTable({
    "pageLength": 10,
    "serverSide": false,
    "destroy": true,
    "ordering": true,
    "searching": false,
    "LengthChange": false,
    "Filter": false,
    "paging": true,
    "language": {
    processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> '
    },
    "order": [[0, "desc"]],
    "ajax": {
    @*"url": "/Home/GetChildTickets1?id="+@ViewBag.id,*@
    "url": "/Db/GetChildTickets?id="+pticket,
    "type": "POST",
    "datatype": "json",
    "dataSrc": function (d) {
    return d
    }
    },

    "columns": [

    {
    "target":"0",
    "data": "Id",
    //"autoWidth": true,
    "render": function (data, type, full) {
    if (type === 'display') {
    var attrDisabled = '';

    // If ticket is closed
    if (full['CurrentStatus'] === 'Closed') {
    // Disable the checkbox
    attrDisabled = 'disabled';
    }
    data = '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '" ' + attrDisabled + '/>';
    }
    return data;
    }
    },
    {
    "title": "Ticket Id", "data": "Id", "name": "Id", "autoWidth": true,
    "render": function (data, type, row, meta) {
    if (type === 'display') {
    data = '<a class="pull-left btn btn-primary btn-xs" href="/Home/Ticket/?id=' + data + '"> <i class="fas fa-hashtag"></i>' + data + ' </a > ';
    }
    return data;
    }
    },
    {
    "title": "Logged On", "data": "CreatedOn", "name": "CreatedOn",
    render: function (data, type, full, meta) {
    if (data !== null) {
    return (moment(data).format("DD/MM/YYYY"));
    } else {
    return '';
    }
    }
    },
    { "title": "Ticket Type", "data": "TypeofWork", "name": "TypeofWork" },
    { "title": "Subject", "data": "Subject", "name": "Subject" },
    { "title": "Contact", "data": "ContactId", "name": "ContactId" },
    { "title": "Status ", "data": "CurrentStatus", "name": "CurrentStatus" },
    { "title": "Team", "data": "Teamid", "name": "Teamid" },
    ],

    });
    }
    }
    enabletemplateListVM.init();









    share|improve this question



























      0












      0








      0








      I want to add data to a datatable when the checkbox of the first table is selected. at the moment when i clicked checkbox1 on the first table the data added to second table but my problem is when i select checkbox2 the data refresh in the the second table and showed the data related to the value of checkbox2. I want the table to show the data from both checkbox as showed by the image below. thanks



      enter image description here



      Datatable1



       $(document).ready(function () {
      var table = $('#tblBulckTicket').DataTable({
      "pageLength": 5
      });
      });


      Datatable2



         // call child ticket
      $("#tblBulckTicket").on('change', "input[type='checkbox']", function (e) {
      tchildticket();

      });


      //Child ticket
      var enabletemplateListVM;
      function tchildticket() {
      var pticket = $('#tblBulckTicket').find('input[type=checkbox]:checked').val();
      enabletemplateListVM = {
      dt: null,
      init: function () {
      dt = $('#childtable').DataTable({
      "pageLength": 10,
      "serverSide": false,
      "destroy": true,
      "ordering": true,
      "searching": false,
      "LengthChange": false,
      "Filter": false,
      "paging": true,
      "language": {
      processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> '
      },
      "order": [[0, "desc"]],
      "ajax": {
      @*"url": "/Home/GetChildTickets1?id="+@ViewBag.id,*@
      "url": "/Db/GetChildTickets?id="+pticket,
      "type": "POST",
      "datatype": "json",
      "dataSrc": function (d) {
      return d
      }
      },

      "columns": [

      {
      "target":"0",
      "data": "Id",
      //"autoWidth": true,
      "render": function (data, type, full) {
      if (type === 'display') {
      var attrDisabled = '';

      // If ticket is closed
      if (full['CurrentStatus'] === 'Closed') {
      // Disable the checkbox
      attrDisabled = 'disabled';
      }
      data = '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '" ' + attrDisabled + '/>';
      }
      return data;
      }
      },
      {
      "title": "Ticket Id", "data": "Id", "name": "Id", "autoWidth": true,
      "render": function (data, type, row, meta) {
      if (type === 'display') {
      data = '<a class="pull-left btn btn-primary btn-xs" href="/Home/Ticket/?id=' + data + '"> <i class="fas fa-hashtag"></i>' + data + ' </a > ';
      }
      return data;
      }
      },
      {
      "title": "Logged On", "data": "CreatedOn", "name": "CreatedOn",
      render: function (data, type, full, meta) {
      if (data !== null) {
      return (moment(data).format("DD/MM/YYYY"));
      } else {
      return '';
      }
      }
      },
      { "title": "Ticket Type", "data": "TypeofWork", "name": "TypeofWork" },
      { "title": "Subject", "data": "Subject", "name": "Subject" },
      { "title": "Contact", "data": "ContactId", "name": "ContactId" },
      { "title": "Status ", "data": "CurrentStatus", "name": "CurrentStatus" },
      { "title": "Team", "data": "Teamid", "name": "Teamid" },
      ],

      });
      }
      }
      enabletemplateListVM.init();









      share|improve this question
















      I want to add data to a datatable when the checkbox of the first table is selected. at the moment when i clicked checkbox1 on the first table the data added to second table but my problem is when i select checkbox2 the data refresh in the the second table and showed the data related to the value of checkbox2. I want the table to show the data from both checkbox as showed by the image below. thanks



      enter image description here



      Datatable1



       $(document).ready(function () {
      var table = $('#tblBulckTicket').DataTable({
      "pageLength": 5
      });
      });


      Datatable2



         // call child ticket
      $("#tblBulckTicket").on('change', "input[type='checkbox']", function (e) {
      tchildticket();

      });


      //Child ticket
      var enabletemplateListVM;
      function tchildticket() {
      var pticket = $('#tblBulckTicket').find('input[type=checkbox]:checked').val();
      enabletemplateListVM = {
      dt: null,
      init: function () {
      dt = $('#childtable').DataTable({
      "pageLength": 10,
      "serverSide": false,
      "destroy": true,
      "ordering": true,
      "searching": false,
      "LengthChange": false,
      "Filter": false,
      "paging": true,
      "language": {
      processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span> '
      },
      "order": [[0, "desc"]],
      "ajax": {
      @*"url": "/Home/GetChildTickets1?id="+@ViewBag.id,*@
      "url": "/Db/GetChildTickets?id="+pticket,
      "type": "POST",
      "datatype": "json",
      "dataSrc": function (d) {
      return d
      }
      },

      "columns": [

      {
      "target":"0",
      "data": "Id",
      //"autoWidth": true,
      "render": function (data, type, full) {
      if (type === 'display') {
      var attrDisabled = '';

      // If ticket is closed
      if (full['CurrentStatus'] === 'Closed') {
      // Disable the checkbox
      attrDisabled = 'disabled';
      }
      data = '<input type="checkbox" id="cticket" name="cticket" value="' + full.Id + '" ' + attrDisabled + '/>';
      }
      return data;
      }
      },
      {
      "title": "Ticket Id", "data": "Id", "name": "Id", "autoWidth": true,
      "render": function (data, type, row, meta) {
      if (type === 'display') {
      data = '<a class="pull-left btn btn-primary btn-xs" href="/Home/Ticket/?id=' + data + '"> <i class="fas fa-hashtag"></i>' + data + ' </a > ';
      }
      return data;
      }
      },
      {
      "title": "Logged On", "data": "CreatedOn", "name": "CreatedOn",
      render: function (data, type, full, meta) {
      if (data !== null) {
      return (moment(data).format("DD/MM/YYYY"));
      } else {
      return '';
      }
      }
      },
      { "title": "Ticket Type", "data": "TypeofWork", "name": "TypeofWork" },
      { "title": "Subject", "data": "Subject", "name": "Subject" },
      { "title": "Contact", "data": "ContactId", "name": "ContactId" },
      { "title": "Status ", "data": "CurrentStatus", "name": "CurrentStatus" },
      { "title": "Team", "data": "Teamid", "name": "Teamid" },
      ],

      });
      }
      }
      enabletemplateListVM.init();






      javascript asp.net-mvc datatables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 18 at 19:31







      Eric Aime Tchatchoua

















      asked Jan 18 at 16:03









      Eric Aime TchatchouaEric Aime Tchatchoua

      477




      477
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257517%2fadd-data-to-datatable-when-the-checkbox-is-selected-using-json-in-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257517%2fadd-data-to-datatable-when-the-checkbox-is-selected-using-json-in-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage