Search code examples
ng2-smart-table

How to connect fire base ng2-smart-table's create data


I have been using the ng2-smart-table template. I could not able to found the location where the data save after click the add new button.some one can help me now.

In this table create data and show in the list the data what we are created. but the case is if we are refresh the browser , the above mentioned data not saved. then what should i do for add those data for firestore.


Solution

  • The DataSource of the mentioned module is simply an array or LocalDataSource object according to Documentation.

    Let's take an example. On typescript file define an array like this.

    data = [
      {
        id: 1,
        name: "Leanne Graham",
        username: "Bret",
        email: "Sincere@april.biz"
      },
      {
        id: 2,
        name: "Ervin Howell",
        username: "Antonette",
        email: "Shanna@melissa.tv"
      },
    
      // ... list of items
    
      {
        id: 11,
        name: "Nicholas DuBuque",
        username: "Nicholas.Stanton",
        email: "Rey.Padberg@rosamond.biz"
      }
    ];
    
    settings = {
      columns: {
        id: {
          title: 'ID'
        },
        name: {
          title: 'Full Name'
        },
        username: {
          title: 'User Name'
        },
        email: {
          title: 'Email'
        }
      },
    add:{
     confirmCreate:true
    },
    mode:'inline'
    };
    

    On template(html).

    <ng2-smart-table (createConfirm)="addData($event)" [settings]="settings"
                           [source]="data"></ng2-smart-table>
    

    Again on template.

    addData(event){
    //event.data is the newely created data
    // Handle newly created data
    // Shape of object is  {
    //    id,
    //    name,
    //    username,
    //    email,
    //  }
    // You must call event.confirm.resolve() to show data on table
    }
    

    Above addData(event) function is called when click ctrate confim.