Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
igGrid: how to replace datasource ?
posted

Hello all,

I'm having troubles with igGrid and datasource option.

I already read this topic and it helps me to find a solution which, unfortunatelly, doesn't work at all.

This is my scenario:

The user had to press a button to add a row to a igGrid. Immediatly after the row is added, the saveChanges is called. If server logics are Ok, a Json result which contains my datasource is returned. In this case I want to bind the igGrid datasource to the returned result.

If I just write $("#grid1").igGrid('option', 'dataSource', data);  data is appended to old data. I want to replace old data with new one.

Those are relevant code lines:

$('#grid1').igGrid(
{
virtualization: false,
//dataSourceUrl: '/Richiesta/getRichiesta',
updateUrl: '/Richiesta/updRichiesta',
autoGenerateColumns: false,
renderCheckboxes: true,
autoGenerateLayouts: false,
mergeUnboundColumns: false,
responseDataKey: 'Records',
generateCompactJSONResponse: false,
enableUTCDates: true,
autoCommit: false,
columns:
 [
 //{ key: 'num_rif_richiesta', dataType: 'number', headerText: 'rif', width: '4em' },
 //{ key: 'num_riga', dataType: 'number', headerText: 'riga', width: '4em' },
 { key: 'cod_tipo_articolo', dataType: 'string', headerText: 'Marchio', width: '4em' },
 { key: 'cod_articolo', dataType: 'string', headerText: 'Codice', width: '6em' },
 { key: 'chkurgente', dataType: 'bool', headerText: 'Urg', width: '3em' },
 { key: 'des_riga', dataType: 'string', headerText: 'Descrizione', width: '10em' },
 { key: 'num_qta', dataType: 'number', headerText: 'Qta', width: '2em', formatter: formatNumero },
 { key: 'numdisponibilita', dataType: 'number', headerText: 'Disp', width: '2em', formatter: formatNumero },
 { key: 'val_prezzo_unitario', dataType: 'number', headerText: 'Prezzo', width: '6em', formatter: formatValuta },
 { key: 'prc_sconto', dataType: 'number', headerText: 'Sconto', width: '4em', formatter: formatPercentuale },
 { key: 'prc_sconto_add', dataType: 'number', headerText: 'Sc Add', width: '4em', formatter: formatPercentuale },
 { key: 'val_importo', dataType: 'number', headerText: 'Netto', width: '6em', formatter: formatValuta },
 { key: 'mat_telaio', dataType: 'string', headerText: 'Telaio', width: '8em' },
 { key: 'des_modello', dataType: 'string', headerText: 'Modello', width: '10em'},
 { key: 'des_note', dataType: 'string', headerText: 'Note', width: 'auto'}
 ],
dataBound: function(evt, ui) {
$("#grid1").data("igGrid").dataSource._addChangesSuccessHandler(function (data, textStatus, jqXHR) {
gridReBind(data);
pulisciRiga();
});
},
features: [
{
name: "Selection",
mode: "row",
multipleSelection: false,
rowSelectionChanging: function (ui, args) { },
rowSelectionChanged: function (ui, args) {
selezionaRiga(args.row.index);

}
},
{
name: "Updating",
enableAddRow: false,
editMode: "none",
enableDeleteRow: false,
showDoneCancelButtons: false
}


],
width: '100%',
localSchemaTransform: false
});

function gridReBind(data) {
$("#grid1").igGrid("rollback");
//$("#grid1").igGrid("dataSourceObject", data);
$("#grid1").igGrid('option', 'dataSource', data);
//$("#grid1").igGrid("dataBind");
}

Thanks in advance

Parents
No Data
Reply Children