Author Topic: Can't get checkboxes to save  (Read 2809 times)

whatismyname

  • Newbie
  • *
  • Posts: 1
    • View Profile
Can't get checkboxes to save
« on: July 07, 2015, 03:18:46 pm »
I am trying to get checkboxes in a grid to save so I can update a database.  Don't know if this is possible in the non-pro version, and can't find any documentation on it.

Here's some code:
var colM = [
      { title: "ID", width: 60, hidden:true },
      { title: "Name" },
      { title: "Freeze" ,dataIndx: 11, editable: true, sortable: false, width: 30, align: "center", resizable: false, render: function (ui) {
              var rowData = ui.rowData, dataIndx = ui.dataIndx;
              var val = rowData[dataIndx];
              str = "";
              if (val == 1) {
                  str = "checked='checked'";
              }
              return "<input type='checkbox' " + str + " />";
          },
          saveCell: function (ui) {
            console.log('ui',ui)
      // Here I would like to update the database using a $.post function
          }
       }
Then I set the colModel option to the colM object above.  This renders the checkbox ok and checks the right ones according to the data, but when I uncheck or check them I can't get anything out of the saveCell function.  I have already checked whether another function is clashing with it.  Does anyone know the proper way to do this?

I also have the problem of the state of the checkbox not saving in the client when I scroll the grid, which was mentioned elsewhere but not answered.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Can't get checkboxes to save
« Reply #1 on: July 07, 2015, 04:42:44 pm »
There is a difference between column.render and column.editor and they should not be confused.

render creates a read only view of the cell and can't make any change in the data on its own. So you have to listen to cellClick event and make change in data yourself. Here is a similar demo that uses checkbox in render http://paramquery.com/demos/selection_custom

Once you save the changed state of checkbox in data, they would be rendered correctly upon scroll.

saveCell event fires only when a change is made in editor, not in case of render.

If you want to use custom editor, there is a demo here http://paramquery.com/demos/editing_custom
« Last Edit: July 07, 2015, 07:17:13 pm by paramquery »