1

i wanna ask you how to make edit function (edit row in data table, then press button) like this in my case. Dont need py update functions only frond end and a bit js(ajax) code for sending data. Picture bellow enter image description here

My data table look like this.

enter image description here

My js code, then press edit button and just asking "Are you sure" and take data table row data.

   $('#calEvents').on( 'click', 'button[name="edit"]', function ()  {
   var data = table.row( $(this).parents('tr') ).data();
  
   var confirmalert = confirm("Are you sure?");
   if (confirmalert == true) {
    
          }else{
        alert('Invalid ID.');
          }
 });

If you help me i will be very gratefull, because now im stuck and idk how to start it. If u need some information ask me in comments. Thank you for your time.

  • "edit function"? What do you mean by that do you want to update the data "live"? – Patch Jul 16 '20 at 07:02
  • it will be nice if update the data life, if not i will use ``` location.reload();``` function. I just wanna get start for data table row edit. In database i will write sql code for update in my self. –  Jul 16 '20 at 07:03
  • I don't understand what you need. Please make the question clearer. – Patch Jul 16 '20 at 07:04
  • i need make function, then you press "Edit button" you will get field in that field you need change some data. Like event text or something like what. Than press update and what row will update with now Event text. Idk how to tell it more clear. It should be like this https://editor.datatables.net/examples/simple/inTableControls.html but idk how to do it in my case. –  Jul 16 '20 at 07:07
  • Just change the element's text with JQuery when you receive the data by doing `$("#element").text("some other text")` – Patch Jul 16 '20 at 07:10
  • how to separate what date is like in my example json data "ENG SM", this? And i dont know how to do second window for edit text. (front end) –  Jul 16 '20 at 07:13
  • For your first question: https://stackoverflow.com/questions/51738251/how-to-get-the-data-from-the-json-list-of-json-list for your second one what do you mean by a "second window" you can just change it how I told you to – Patch Jul 16 '20 at 07:38
  • editor.datatables.net/examples/simple/inTableControls.html in this example press "Edit" and you will see second window curved on first window, i wanna make it too. And i wanna ask you why i need make some elements if i can just go data[0] or data[1] and get data element what i need? like "ENG SM" or something like what –  Jul 16 '20 at 07:44
  • Use modal... It's in the same url... You will be able to then change the data according to what I said. If you want to make it data[0] etc' go ahead... I showed you a more comparable way of doing that... You can do it however you want – Patch Jul 16 '20 at 07:48
  • Can u write some example how to be look modal? im now in here hard understand how customize what example in my case please. –  Jul 16 '20 at 07:51
  • Well you can use bootstrap https://getbootstrap.com/docs/4.0/components/modal/ if you want I can post an answer but it's going to be more of a general on how to do stuff with a little bit code... – Patch Jul 16 '20 at 07:53
  • Ty, i will try with your given example's, if u have time post the code, i will be very gratefull for the help. –  Jul 16 '20 at 07:58

1 Answers1

1

I found solution, in js edit code need add just

$('#myModal').modal('show');

and then create in html code modal form

<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
  <textarea class="form-control" id="testforit"  value="hello" rows="2"> 
     </textarea>
    <p>Some text in the Modal..</p>
  </div>

</div>

something like what

then in value text, you can add info from the row like this

document.getElementById("testforit").value = "test";