Is it possible to save the values of sheet 1, sheet 2 in a mysql db in spreadsheet ?

I have like two sheets like sheet 1 and 2. When i add some text to the sheet 1 it saves successfully but if i do on sheet 2 its saving in sheet 1 rather than sheet 2.
If its possible could someone give me the PHP code for that. I’m using a trial version of the spreadsheet.

Hello,

We don’t have ready-made php examples for your case, but there’s something else for you to consider.

Current Spreadsheet API presupposes that there’s a single sheet in the view. To correctly save multisheet data you need to send all the data to server after each change:

save:{
   data:{
     $proxy:true,
     save:function(view, data){
         data = {data:view.serialize({sheets:true})};
         webix.ajax().post("server/data.php?sheet=3", data);
     }
   }
}

E.g. https://webix.com/snippet/4757b8ce

Thanks for your valuable effort. The snippet above will save the data in the db if i mention it like sheet=3 or sheet=2 etc. But i wanted a more dynamic way of assigning the sheet numbers when webix.ajax().post(“server/data.php?sheet=3”, data); is called.

But i figured out to do that will session.

Sorry to be that ambiguous. This url doesn’t point to any sheet, it was taken from our samples and it points to the 3rd Spreadsheet in our database.

The idea is that to save data per sheet, you need to collect all the data from all the sheets with spreadsheet.serialize({sheets:true}) method and then save the whole data into the database.

The data for multiple sheets that comes from the server during reloading, should be as follows:

{ sheets: [
   { 
      name: "Tab 1", 
      content:{ 
         data:[], ..etc
      }
   },
   {
      name: "Tab 2",
      content:{
         data:[], ..etc
      }
   }
]}

Also, if needed, you can pass the name of the active sheet to server: https://webix.com/snippet/02d0f9b2. But it is not safe as sheet names can be changed by user. The correct way was described above.

In this snippet could you give the code for how image can be uploaded.

save: {
        data:{
          $proxy:true,
          save:function(view, data){
            data.sheet = view.getActiveSheet();
            webix.ajax().post("server/data.php", data);
          }
        },
images:{
??????
},
        //same proxy
        sizes:{},
        spans:{},
        styles:{}
      },

The images are stored in Spreadsheet serialized data object as either base64 strings or links:

data:[
    //cell with an uploaded image
    [10, 4, "=IMAGE('data:image/png;base64,iVBORw...')"],
    //cell with an image link
    [10, 5,"=IMAGE("http://some.jpg")"]
]

You can add images to your Spreadsheet and then inspect the result of spreadsheet.serialize({sheets:true}) in your browser console.

Then the database becomes very heavy. Is there a possiblity to add only the link and save it to the database.

hey i simply put this
save: {
data:{
$proxy:true,
save:function(view, data){
data.sheet = view.getActiveSheet();
//alert(data.sheet)
webix.ajax().post(“server/data.php”, data);
}
},
sizes:{
$proxy:true,
save:function(view, data){
data.sheet = view.getActiveSheet();
webix.ajax().post(“server/sizes.php”, data);
}
},
spans:{
$proxy:true,
save:function(view, data){
data.sheet = view.getActiveSheet();
webix.ajax().post(“server/spans.php”, data);
}
},
styles:{
$proxy:true,
save:function(view, data){
data.sheet = view.getActiveSheet();
//alert(data.sheet)
webix.ajax().post(“server/styles.php”, data);
}
},
images:“server/image.php”
},

Worked like a charm.

Beware to save the data when a user rename the sheet:

spreadsheet.attachEvent("onSheetRename", function(name, newName){
   ...save data
});

yes yes yes it worked too…

Is there any proxy method for uploading images. Actually i wanted to send the sheet name to the server.

Something like the below code:-

images:{
$proxy:true,
save:function(view, data){
data.sheet = view.getActiveSheet();
//alert(data.sheet)
webix.ajax().post(“server/images.php”, data);
}