Slicers provide an easy and efficient way for users to filter table data quickly. SpreadJS slicers allow the developer to customize the types of filters they want to provide to the users and these slicers can be used with different types of UI and JavaScript libraries. A very common use of slicers are the filter panels you see on common product websites such as Amazon.com. When you narrow your list down by price and brand, for example, you are using a slicer. In this article, we use a SpreadJS custom slicer to create a filter panel that helps us narrow a list of classic cars. We used an ASP.NET Web project in Visual Studio, but you can use the development environment of your choice. The final result will look like this: The final result of our project will be a table with a filter panel. To download the sample used in this blog, click here: SpreadJS Custom Slicer To read more about using slicers in SpreadJS, click here: http://spread.grapecity.com/Demos/JS/TutorialSample/#/samples/generalSlicerData
Set Up the Project
Create a new empty ASP.NET Web project, and add a new html file in Visual Studio 2015. In this file, add references to the SpreadJS script and css files, as well as the noUiSlider and jQuery script files:
Once this is done, add a script to the page to contain the slicer code as well as a div element that represents the Spread component:
Load Data
Define a JavaScript function that loads a JSON file via an XMLHttpRequest:
After that, call that function and create a new function to pass in as the callback. In this callback function, define the variables that will be passed in as column names and data:
Programmatically create a table that will be appended to the spreadsheet div in order to contain and format the data:
Create Slicers
In this sample, there are two custom slicers that are used for four different properties. The first slicer is for selecting a set number of variables to filter by using check boxes:
The second slicer is for selecting a range of data with sliders:
Place Slicers
In the body of the HTML page, add a div for each slicer:
Then, in the loadJSON callback, attach the slicers to the div elements after the call to init():
In this tutorial, SpreadJS slicers were used to customize how data is filtered by the user. The data was loaded from a JSON file, and then that data was used to populate a table which could be filtered using the SpreadJS slicers. Slicers allow users to filter data quickly without needing a drop-down menu. To learn more about SpreadJS and to download a trial, click here: http://spread.grapecity.com/spreadJS/