jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Don't get data on page first load
This topic contains 4 replies, has 2 voices, and was last updated by romulocpd 10 years ago.
-
Author
-
Hello.
The JQXGrid is working very well, but I have a problem.
Just the page load the DataSource is loaded and the grid is loaded too. I need the grid be loaded just when I click on the button and raise a POST to get data (via ajax)
var sourceGrid = { dataType: 'json', id: 'Id', url: '@Url.Action("ObterAbastecimentosJSON", "Abastecimento", new { area = "Manutencao" })', dataFields: [ { name: 'Id', type: 'number' }, { name: 'NumeroFormulario', type: 'number' }, { name: 'TipoAbastecimento', type: 'string' }, { name: 'TipoEstoque', type: 'string' }, { name: 'LocalEstoque', type: 'string' }, { name: 'QtdEquipamentos', type: 'number' }, { name: 'QtdLitros', type: 'number' }, { name: 'ValorAbastecimento', type: 'number' }, { name: 'Posto', type: 'string' }, { name: 'DataAbastecimento', type: 'date' }, { name: 'Empresa', type: 'string' }, { name: 'BaseOperacional', type: 'string' }, { name: 'Equipamento', type: 'string' }, { name: 'Colaborador', type: 'string' }, { name: 'Usuario', type: 'string' } ] }; var dataAdapter = new $.jqx.dataAdapter(sourceGrid);
The sourceGrid is faired just the page is load at first time.
Thank you
Hello romulocpd,
If you wish the grid to appear only after the button click, initialize it in the Ajax call’s success callback, not in $(document).ready(). If you wish the grid to be empty initially (showing “No data to display”) and be populated when you click the button, set its source property in the Ajax call’s success callback.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hello.
I’ve solved the problem.
$("#Grid").jqxGrid('clear'); $("#Grid").jqxGrid({ source: dataAdapter });
Is it the better way?
Thank you.
Hello romulocpd,
This is a correct approach but there is no need to clear the grid, just reset its source.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hello Dimitar.
If I don’t clear the grid an error occours.
`jqxgrid.filter.js:7 Uncaught TypeError: Cannot read property ‘0’ of null’
But works!
-
AuthorPosts
You must be logged in to reply to this topic.