data current row of hidden column after editing

data current row of hidden column after editing

nikishinnikishin Posts: 4Questions: 2Answers: 0
edited November 2023 in Free community support

Hi all. I have a dynamic table with different number of columns. Some columns are hidden. When I edit cells I am unable to get the cell data. This design sees only visible cells. how to access hidden columns?

 $(document).on('click','#Save',function()
 {
  var sql_string="";
  var columns = [];

  var currentRow=$(this).closest("tr");
  var count_rows = document.getElementById('example').rows[0].cells.length;


  for (i = 0; i < count_rows; ++i) 
  {
    if (i>3)
    {

      start = currentRow.find("td:eq("+(i+1)+")").text().substring(0,5);
      if (start == "")
      {
        start = "00:00";
      }
      end   = currentRow.find("td:eq("+(i+1)+")").text().substring(6,11);
      if (end == "")
      {
        end = "00:00";
      }

      sql_string = sql_string + "UPDATE `Working_hours_plan` SET `start_time`='"+start+"',`end_time`='"+end+
                                "' WHERE `id`="+currentRow.find("td:eq("+i+")").text()+";";
      i = i + 1;            
    }
  }

  alert(sql_string);

  $.ajax({
        method: "POST", 
        url: "Workdays_spec_update_plan.php", 
        data: { sql_string    : sql_string,},
        success: function(data) 
        {
          if (data)
          {
            alert("ok ");
          }
          else
          {
            alert("not ok");
          }
        }
      });

  $(this).closest('tr').find('[name="noneditable"]').hide('fast');
  $(this).closest('tr').find('[name="editable"]').show('fast');

  var currentTD = $(this).parents('tr').find('td');
  $.each(currentTD, function () 
  {
    if (i>4)
    {
      $(this).prop('contenteditable', false)
    }
    i = i +1;
  });

 });

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • nikishinnikishin Posts: 4Questions: 2Answers: 0
    var currentRow = $(this).closest("tr");
    
    var data = $('#myTable').DataTable().row(currentRow).data();
    

    this solution sees hidden fields but does not display edited data

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    this solution sees hidden fields but does not display edited data

    I might be missing it but how are you updating the table cells? For Datatables to know about the updates you will need to use Datatables APIs. See this FAQ.

    Kevin

  • nikishinnikishin Posts: 4Questions: 2Answers: 0

    I set contenteditable

    $(document).on('click','#Edit',function()
    {
    i = 1;
    var currentTD = $(this).parents('tr').find('td');
    $.each(currentTD, function ()
    {
    if (i>4)
    {
    $(this).prop('contenteditable', true)
    }
    i = i +1;
    });

    $(this).closest('tr').find('[name="noneditable"]').show('fast');
    $(this).closest('tr').find('[name="editable"]').hide('fast');

    var currentRow=$(this).closest("tr");
    currentRow.find("td:eq(5)").focus();

    });

Sign In or Register to comment.