My first blog post of 2014 covers a couple of tips and tricks all of us can use: common customizations for SpreadJS. In this article, we will discuss following two customizations :

  1. HowTo: Retain the insignificant zero entered at the end of a decimal value
  2. HowTo: Lload ssjson file created from SpreadJS designer in SpreadJS

HowTo: Retain the insignificant zero entered at the end of a decimal value

Currently, when the user enters a decimal value in the cell which ends with '0', then SpreadJS rounds off the value and does not displays the last insignificant zero. In certain scenarios the user would like to display the last zero. With this tip, you can retain the last zero. You would need to set the format of the cell to text so that it accepts all the alphanumeric value as they are entered and does not parse the value further. Following code is used to set the format of the cell to Text format:

var sheet = $("#ss").wijspread("spread").getActiveSheet(); sheet.getCell(0, 0).formatter("@");

Here is the complete code:

<script type="text/javascript">     $(document).ready(function () {         $("#ss").wijspread({             sheetCount: 1         });         var sheet = $("#ss").wijspread("spread").getActiveSheet();         sheet.getCell(0, 0).formatter("@");     }); </script> <body>     <div id="ss" style="width: 100%; height: 450px; border: 1px solid gray;"></div> </body>

HowTo: Load ssjson file created from SpreadJS designer in SpreadJS

SpreadJS designer lets you design and save SpreadSheets in ssjson format. You can later load this ssjson file into SpreadJS widget so as to design the widget without having to write code in JQuery. You can use the following code to load ssjson file in SpreadJS widget:

$(document).ready(function () {     $(“#ss1″).wijspread({ sheetCount: 1 });     var spread1 = $(“#ss1″).wijspread(“spread”);     $.ajax({         url: “Test.ssjson”,         datatype: “json”,         success: function (data) {             //here to load ssjson file.             spread1.isPaintSuspended(true);             spread1.fromJSON(JSON.parse(data));             spread1.isPaintSuspended(false);         },         error: function (ex) {         alert(ex);     }     }); });

WrapUp

We will be adding some more customizations on SpreadJS soon. Let me know if you have some questions on these customizations.