Populate a datatbale with selected rows from another datatble
Populate a datatbale with selected rows from another datatble

I am using Editor
I have two different datatbles promotions_index table and promotions_forms table in database. I want the the promotions_index table to be inserted with the rows pre-populated in promotions_forms.
I saw this link : http://live.datatables.net/koxezeyu/1/edit but the problem is that my tables are on two different pages not inside one script
What I am trying to do is that, capturing the data and sending it to the server, from where I can insert in another table.
the **console.log(abc);
** is showing me no data and I dont know why
var abc = table.rows().data().toArray();
// console.log(abc);
$.ajax({
type: 'POST',
url: 'my.txt',
dataType: 'json',
data: {json: JSON.stringify(abc)},
success: function (data) {
alert(json);
console.log(json);
}
});
Can you please give me an idea how can I do it ?
This question has an accepted answers - jump to answer
Answers
What is the result?
You haven't shown enough code for us to help debug the problem. Best thing is to provide a link to your page or a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren Thanks for the prompt reply.
console.log(abc) displays an empty array like this** []**. However, the datatable gets populated successfully
My problem is that I have two tables inside one database and I want to insert the rows from table-1 into table-2 based on some conditions.
Something similar to this http://live.datatables.net/koxezeyu/1/edit but my issue is that I am just displaying one Datatable on one page.
I am not sure how to replicate it when you have data coming from the database? I will look into it and try to make one. Thank you
Possibly you are using
var abc = table.rows().data().toArray();
before Datatables is populated via the ajax request. Are you usingvar abc = table.rows().data().toArray();
inside a click event?Kevin
@kthorngren
No, it is not inside click event . please find my code below.
@kthorngren update , when I put it inside click event it works fine, the array is populated with data and I can see it in console.log. However, it doesn't get saved in 'my.txt' file which I have given in** url: 'my.txt'**
@kthorngren please ignore my above two comments.
I have a latest update:
I got what I am trying to do :
1) reading the rows from data table based on search applied
2) passing that data to the server using:
3) on server.php I can read all the data and I validated it using url-encoded json tool
**4) The issue now is , how can I retrieve that data (from url encode) and fill another table under same database? **
Your help is highly appreciated
I'd suggest you add
type: 'post'
into your$.ajax
object. Then on the server-side you would use:from there, how you insert it into the database is up to you.
Allan
@allan Thanks I managed to solve my problem.
Received the data via
$data = json_decode( $_POST['json'] );
and inserted the JSON format data in MySQL database with php