Dex12345
Dex12345

Reputation: 11

Remove last three columns of Handsontable

I have a simple Handsontable that displays some data from a MySQL table. Unfortunately I'm retrieving too much data and I need to remove or hide the added columns. I've searched on the internet and it does seem possible, but every example I have found doesn't seem to work.

results.jsp

<script>
    var data = ${jsonProducts}; 
    var ht = new Handsontable(dataTable, {
        data: data,    
        startRows: data.length,
        readOnly: true,
        maxCols: 7,
        colHeaders: true,
        colHeaders: ["Id", "Problem", "Solution", "Deadline", "Type", "Status", "Developer"],            
    });
</script>

I tried maxCols: 7 but this doesn't work.

This is how i'm retrieving the data (not that's it's relevant to the question)

@RequestMapping(value = "/result", method = RequestMethod.GET)
public String defaultView(Model model) {
    Iterable<Request> request = requestRepository.findAll();  
    model.addAttribute("requests", request);
    Gson gson = new Gson();
    String json = gson.toJson(request); 
    model.addAttribute("jsonProducts", json);
    return "form/result";
}

This is what the table looks like currently: current state of Handsontable

I would like to show only the first 7 columns and hide the last 3.

Any help would be greatly appreciated.

Upvotes: 0

Views: 222

Answers (1)

Rubysmith
Rubysmith

Reputation: 1175

You need to explicitly define the columns you want to display in your grid from the original array of arrays data source in such a case. For example:

<script>
var data = ${jsonProducts}; 
var ht = new Handsontable(dataTable, {
    data: data,    
    startRows: data.length,
    readOnly: true,
    maxCols: 7,
    columns: [{ data: 0, type: 'text' }, { data: 1, type: 'text' }, { data: 2, type: 'text' }, { data: 3, type: 'text' }, { data: 4, type: 'text'}],
    colHeaders: true,
    colHeaders: ["Id", "Problem", "Solution", "Deadline", "Type", "Status", "Developer"],            
});
</script>

Upvotes: 1

Related Questions