Hi,
I have a html page which host jquery grid and it binded to hard coded Json data. Note that I have set autoGenerateColumns property to true. Also I have added a button, on click of that i am trying to rebind the grid with new data.
If new data is having same number of columns and same name then it works fine. Grid reflects the data. But if new data is having completely new columns then it do not get reflected in UI. It removes all the data rows but the header still shows old column names.
I also tried using destroy but it completely removes the grids from UI.
Following is my HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" href="SamplesBrowser/SamplesCommon/jQuery/Styles/min/ig/jquery.ui.custom.min.css" rel="stylesheet" />
<link type="text/css" href="SamplesBrowser/SamplesCommon/jQuery/Styles/base/ig.ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="SamplesBrowser/Scripts/jquery.js"></script>
<script type="text/javascript" src="SamplesBrowser/Scripts/jquery-ui.js"></script>
<script type="text/javascript" src="SamplesBrowser/SamplesCommon/jQuery/Scripts/combined/min/ig.ui.min.js"></script>
<script type="text/javascript" src="SamplesBrowser/Scripts/jquery.tmpl.js"></script>
<script type="text/javascript">
var products = [];
products[0] = { "ProductID": 1, "Name": "Adjustable Race", "ProductNumber": "AR-5381" };
products[1] = { "ProductID": 2, "Name": "Bearing Ball", "ProductNumber": "BA-8327" };
products[2] = { "ProductID": 3, "Name": "BB Ball Bearing", "ProductNumber": "BE-2349" };
var jsonData = [];
jsonData[0] = { "EmployeeID": 1, "EmployeeName": "Samuel Das" };
jsonData[1] = { "EmployeeID": 2, "EmployeeName": "Steve Austin" };
$(window).load(function () {
$("#grid1").igGrid({
autoGenerateColumns: true,
dataSource: products
});
function ReLoadData() {
//$('#grid1').igGrid('destroy');
//$('#grid1').igGridUpdating( "destroy" );
$('#grid1').igGrid('dataSourceObject', jsonData);
$('#grid1').igGrid('dataBind');
}
</script>
<h1>
igGrid - AutoGenerateColumns
</h1>
<input type="submit" onclick="ReLoadData();" value="Reload" />
</head>
<body>
<br>
<table id="grid1">
</table>
</body>
</html>
Any help or suggestions will be appreciated.
I am having this issue now with the latest version. Resetting the datasource on the grid doesn't change the previous Auto-Generated columns. If i try to destroy and recreate the grid like was done above, nothing runs after i call the destroy method. Not sure what I am doing wrong here.
<div id="gridDisplay"></div>
function ShowOnScreen(reportID, storedProcedure) { var displayDiv = document.getElementById('divShowOnScreen'); var title = document.getElementById('displayTitle');
$.post('@Url.Action("PopulateDisplayGrid")', { "ReportID": reportID, "StoredProcedure": storedProcedure }).success(GridSuccess)
function GridSuccess(data) { title.innerHTML = data.Title;
$("#gridDisplay").igGrid("destory");
var ds = new $.ig.DataSource({ type: "json", dataSource: data.Grid }); ds.dataBind();
$("#gridDisplay").igGrid({ autoGenerateColumns: true, //width: "100%", dataSource: ds, features: [ { name: "Paging", type: "local", pageSize: 10, pageSizeDropDownLocation: "inpager" } ], });
displayDiv.style.display = 'inline'; } }
@@Martin Pavlov : Thanks for the quick response. Your 2nd option works perfectly for my scenario what you have given....
But yesterday i was trying to destroy whole grid while reloading with new data by re initializing from scratch by using $(grd).igGrid('destroy'); which was not working for me which i found the problem was with the table element. then I changed table element to div then it woks fine. I just mentioned might be useful for someone..
Hello Abhijit,You don't need to create an $.ig.DataSource instance. Actually igGrid creates one behind the scenes.Here are 2 approaches which you can try:Approach 1Just pass your data source url (which returns a valid JSON data) to the "dataSource" setting of igGrid like this:
$(grd).igGrid({width: gridWidth,autoGenerateColumns: false,columns:columns,dataSource: "http://your_data_source_url",features: oSettings});
Then in your button click event you need to call the igGrid.dataBind API like this:$(grd).igGrid("dataBind");
Approach 2If Approach 1 doesn't work for you try to set the new data source (in your button click function) with the following API
$(grd).igGrid("option", "dataSource", newjson);
Hope this helps,Martin PavlovInfragistics, Inc.
Thanks for the reply. But i am not able to refresh the grid. I have binded the datasource with new data but dnt know how i can fresh the data.
My scenario: on button click i will get new json data from ajax call and data will pass to datasource for igGrid. and coloumn array defined in the jquery file
Please find below code for my changes.
if you suggest any any sample code or documentation for rebinding the grid with new datasource in jquery. Its urgent please reply.
function reloadgrid(newjson) { $(function () { ds = new $.ig.DataSource({ dataSource: newjson });
ds.dataBind(); $(gridId).igGrid("dataBind"); }); }
Hello Abhijit,
The error you get means that the igGrid instance is not destroyed. jQuery UI version 1.9 introduced a breaking change of how the widget instances are kept in the .data() function. We provide a fix for this breaking change in Ignite UI 13.1 onward.
Because you have 12.1 RTM you have two options:
1.Use a jQuery UI version below 1.9.
2.Use a igGrid.dataBind API to rebind the grid - the grid igGrid.dataBind API will reload the data from the data source (if the data source is remote url it will make a request to this url automatically) without the need to re-create the grid.