Select in database and Add to new form to print or send mail

Hi im wonderin if it’s possible

  1. the table1 is connected to the database
  2. i have the buttons “add” “delete” “print” “send”
  3. the table 1 shows the given database, so I want select and add to another table.
    in another table it will shows all the item that you selected, that you can add QTY.
    And if I change my mind i click the button “delete” and choose another in table1.
  4. After selecting items in table1 I want to click the button “print” or “send” via email.

is this possible??

Hello okhardwareht,

It is possible to apply the Add, Delete functionalities by simply adding and deleting the selected rows from the second table’s data set. Here how it goes:

  • create two tables, and two data sets , one for each table

  • create an array to hold all the selected rows (you can only select one row at a time so this array will keep all the rows values that you have selected)

  • when clicking add, insert the items selected to table2’s data set. here’s a code to show how:

 
import wixData from 'wix-data';

let selected = []; // this array will hold the selected rows

export function table1_rowSelect(event, $w) {
    let selectedRow = event.rowData;
    selected.push(selectedRow);
}

// add elements selected from table1 to table2 
export function add_click(event, $w) {
    selected.forEach((element, i)=>{
    let toInsert = {
        "title":  element.title,
     };

     wixData.insert("table2", toInsert)
     .then( (results) => {
         let item = results; 
          $w('#dataset2').refresh();
     } )
      .catch( (err) => {
          let errorMsg = err;
       } );
    })
    selected = []; // after adding empty the selected array
}
  • to delete selected rows you can do the same thing but using .remove(). this way you remove selected rows from the table’s data set. check this link to know more how can you insert and remove from data sets: wix-data - Velo API Reference - Wix.com

To send an email i suggest reading this article :

it shows how to send an email on form submission. you’ll have to change what event your handling (here it’s form submission event, you want to change it to send_button on click event).

As for printing a table, it’s not possible at this time.
(check this answer for more details/alternative solution : https://www.wix.com/code/home/forum/feature-requests/simple-print-function-window-print-urgently-requested)

Good luck!
Massa

can i know which permission should i use? i mean in collection permissions…

Hello Okhardwareht ,

in the Dataset settings, set the mode to read and write.

In the Database permissions , set the permission to custom use. As you decide who can read/create content/delete content/…, based on your website visitors.

Massa

Thank you! thumbs up! im finding a way to print through table 2 :slight_smile: thank you thank you