Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / how access igGrid dataSource after REST bind?

how access igGrid dataSource after REST bind?

New Discussion
Andrew Soldan
Andrew Soldan asked on Mar 10, 2020 4:45 PM

Hi,

I want use template for one igGrid column after it is filled with REST data

and somehow cannot access data loaded in the grid like below code,

dataSource = $(“#grid1”).igGrid(“option”, “dataSource”);  is empty…..

$(‘#grid1’).igGrid({
requestType: “POST”,
dataSource: ‘/Home/GridGetData’,
autoGenerateLayouts: false,
autoGenerateColumns: false,
mergeUnboundColumns: false,
responseDataKey: ‘Records’,
generateCompactJSONResponse: false,

rendered: function (evt, ui) {
tmpl = “<div id=grdlist_${ProductID}></div>”;
$(‘#grid1’).igGrid(‘setColumnTemplate’, ‘Name’, tmpl);

},
columns: [
{  key: ‘ProductID’, dataType: ‘number’, headerText: ‘ID’, width: ‘116px’},
{  key: ‘Name’, dataType: ‘string’, headerText: ‘Name’, width: ‘117px’   },
{  key: ‘ListPrice’, dataType: ‘number’, headerText: ‘Price’, width: ‘117px’ },
{  key: ‘ModifiedDate’, dataType: ‘date’, headerText: ‘Date’, width: ‘116px’ }
],
features: [
{
name: ‘Paging’,
recordCountKey: ‘TotalRecordsCount’,
pageIndexUrlKey: ‘page’,
pageSizeUrlKey: ‘pageSize’,
pageSize: 10,
type: ‘remote’,
pageIndexChanging: function (evt, ui) {
var ds = $(“#grid1”).data(‘igGrid’).dataSource;
ds.settings.urlParamsEncoded = function (item, params) {
params.extraParams = {
input: “text here”
};
};
}
}],
height: ‘500px’,
width: ‘100%’,
localSchemaTransform: true
});

/////////////////////////////////////////////

//ds is empty

dataSource = $(“#grid1”).igGrid(“option”, “dataSource”);
$.each(dataSource, function (index, row) {

…………………………………….
});
});

why?

thanks

Sign In to post a reply

Replies

  • 0
    Martin Asenov
    Martin Asenov answered on Mar 9, 2020 3:10 PM

    Hello,

    Thank you for posting in our community.

    The syntax for getting the data source in the provided code snippet will return the original data source used when initializing the grid which will be empty since the request is not finished by the time the grid is initialized. To get the igDataSource instance use the following syntax:

    
    var igDs = $(".selector").data("igGrid").dataSource;
    

    My suggestion is to use the dataBound event to retrieve the data when it is returned from the server after the POST request.

    • 0
      Andrew Soldan
      Andrew Soldan answered on Mar 9, 2020 10:19 PM

      thanks, started using dataBound event as suggested and dataSource is not null anymore,  with local data no problem but with POST  when I use your syntax: dataSource = $("#grid1").data("igGrid").dataSource; I'm getting null in row enumeration, although there is data now there in dataSource._data:

        $.each(dataSource, function (index, row) {
                      $("#grdlist_" + row.ProductID).CustomList({

      error: can't read property ProducID of null

      when I use this statement:  dataSource = $("#grid1").igGrid("option", "dataSource"); which works with local data I got error: cannot use 'in' operator in search for length

      what am I doing wrong here?

      • 0
        Martin Asenov
        Martin Asenov answered on Mar 10, 2020 4:45 PM

        Hello,

        By using this syntax the igDataSource instance is retrieved. To iterate over the data, you have to call the data function:

        var ds = $("#grid1").data('igGrid').dataSource.data();
        

        I have created and attached a sample for your reference. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach in in this case.

        Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.

        Thank you for your cooperation.

        Attachments:
  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Andrew Soldan
Favorites
0
Replies
3
Created On
Mar 10, 2020
Last Post
5 years, 11 months ago

Suggested Discussions

Created by

Created on

Mar 10, 2020 4:45 PM

Last activity on

Feb 12, 2026 3:20 PM