Pergunta

Actually I have implemented a REST solution to POST, PUT and DELETE data from the NavGrid on jQGrid.

Now in the actions buttons for each row, I try to do the same, but i don't know how generate a dynamic url on default formatter actions.

I try with this:

colModel : [
          {name:'actions', index:'', width:80, fixed:true, sortable:false, resize:false,
              formatter:'actions', 
              formatoptions:{ 
                  url: function(cellValue, rowId, rowData){
                      return restPutURL + '/' + rowId ;
                  },
                  mtype: 'PUT',
                  keys:true,
                  delOptions:{
                      url: restDelURL,
                      recreateForm: true, 
                      beforeShowForm:beforeDeleteCallback,
                      onclickSubmit :function(params, postdata) {
                        params.url += '/' + postdata;
                      }
                  }
              }
          },
          { ...my cols.. }
       ]

Delete action is ok, but edit doesn't work. When a row is saved jQGrid send function as part of the URI:

system/function%20(cellValue,%20rowId,%20rowData)%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20console.log(cellValue);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20/system/function%20(cellValue,%20rowId,%20rowData)%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

How I can create a dynamic URI? or, how I can add the id of the edited row to the URI?

Foi útil?

Solução

If you use current version of jqGrid you can use beforeSaveRow callback to make some actions, like modification of URL, before the row will be saved. Unfortunately formatter: "actions" don't allow you to set beforeSaveRow callback, but you can still use $.jgrid.inlineEdit to do this. The corresponding code could be something like

$.extend(true, $.jgrid.inlineEdit, {
    beforeSaveRow: function (option, rowId) {
        option.url = restPutURL + '/' + rowId;
    }
});

or

$.extend(true, $.jgrid.inlineEdit, {
    beforeSaveRow: function (option, rowId) {
        option.url = this.p.editurl + '/' + rowId;
    }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top