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
330
Grid dataBind remote method
posted

Folks,

I have been attempting to bind to a grid using a remote method in aspx with no luck.    The following is the grid definition:

$("#igResults").igGrid({

defaultColumnWidth: 100,

alternateRowStyles: false,

columns: [

{ headerText: "Add?", key: "IsSelected", dataType: "string", width: "50px", columnCssClass: "defaultColumn" },

{ headerText: "Ticker", key: "Ticker", dataType: "string", width: "50px", columnCssClass: "defaultColumn" },

{ headerText: "Cusip", key: "Cusip", dataType: "string", width: "50px", columnCssClass: "defaultColumn" },

{ headerText: "Name", key: "SecurityName", dataType: "string", width: "95px", columnCssClass: "defaultColumn" },

{ headerText: "Starmine Portfolio", key: "StarminePortfolioName", dataType: "string", width: "95px", columnCssClass: "defaultColumn" },

{ headerText: "Start Date", key: "StartDate", dataType: "date", width: "75px", columnCssClass: "defaultColumn" },

{ headerText: "End Date", key: "EndDate", dataType: "date", width: "75px", columnCssClass: "defaultColumn" },

{ headerText: "Startmine Analyst", key: "StarmineAnalystName", dataType: "string", width: "90px", columnCssClass: "defaultColumn" },

{ headerText: "Analyst Region", key: "AnalystRegionName", dataType: "string", width: "90px", columnCssClass: "defaultColumn" },

{ headerText: "MFS Region", key: "MfsRegionName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "MFS Country", key: "MfsCountryName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "MFS Sector", key: "MfsSectorName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "Global Sector", key: "GlobalSectorName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "Mfs Industry", key: "MfsIndustryName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "Factset Industry", key: "FrsIndustryName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" },

{ headerText: "MFS Analyst", key: "MfsAnalystName", dataType: "string", width: "90px", columnCssClass: "defaultColumn" },

{ headerText: "Universe", key: "CoverageUniverseName", dataType: "string", width: "70px", columnCssClass: "defaultColumn" }

],

// primaryKey: "Cusip,StartDate",

requestType : "POST",

dataSourceUrl: "StarminePortfolios.aspx/GetData",

responseDataKey: "d",

caption: "Coverage Universe Override",

autoGenerateColumns: false,

features: [

{

name: "Sorting",

type: "local"

},

{

name: "Paging",

type: "remote",

pageSize: 50,

recordCountKey: "recordCountKey",

pageSizeUrlKey: "pageSize",

pageIndexUrlKey: "pageIndex",

pageIndexChanging: function (event, args) {

// FilterGrid();

alert('here')

},

pageIndexChanged: function (event, args) {

// alert('Here')

}

}

]

});

This is the method that gets called:

function FilterGrid() {

 

 

 

var qryStr = 'tickerList=' + $('#txtTickerList').val() + '&mfsAnalystId=' + StringListValue('#lstMFSAnalystFilter') + '&frsIndustry=' + StringListValue('#lstFRSIndustryFilter') +

'&mfsIndustry=' + StringListValue('#lstMFSIndustryFilter') + '&mfsRegion=' + StringListValue('#lstMFSRegionFilter') + '&analystRegion=' + StringListValue('#lstAnalystRegionFilter') +

'&mfsCountry=' + StringListValue('#lstMFSCountryFilter') + '&mfsSector=' + StringListValue('#lstMFSSectorFilter') +

'&globalSector=' + StringListValue('#lstGlobalSectorFilter') + '&coverageUniverse=' + StringListValue('#lstCoverageUniverse') + '&starminePortfolioId=' + StringListValue('#lstStarminePortfolioFilter') +

'&starmineAnalystId=' + StringListValue('#lstStarmineAnalystFilter') + '&currentStarminePortsOnly=' + $('#chkCurrentStarminePortsOnly').prop('checked');

 

var url = "StarminePortfolios.aspx/GetData?" + qryStr;

$("#igResults").igGrid("option", "dataSource", url);

$("#igResults").igGrid("dataBind");

 

}

On the aspx side this is the WebMethod:

[System.Web.Services.WebMethod(EnableSession = true)]

public static List<StarminePortfoliosSecurity> GetData( string tickerList,string mfsAnalystId,string frsIndustry,

string mfsIndustry, string mfsRegion, string analystRegion,string mfsCountry,string mfsSector,

string globalSector, string coverageUniverse, string starminePortfolioId, string starmineAnalystId, bool currentStarminePortsOnly = true, int pageIndex = 0, int pageSize = 100 )

{

string userLoginId = HttpContext.Current.Session["NT_LOGINID"].ToString();

List<StarminePortfoliosSecurity> list = Mfs.Invest.InvestData.AnalystCoverage.StarminePortfoliosSecurity.GetStarminePortfolioSecuritiesV2(tickerList, mfsAnalystId, frsIndustry, mfsIndustry, mfsRegion, analystRegion, mfsCountry, mfsSector, globalSector, coverageUniverse, starminePortfolioId, starmineAnalystId, currentStarminePortsOnly);

return list;

}

I keep getting a 500 error message because it does not understand the request.   I am able to do this with $ajax but I really need to work thru the grid.   Can you tell me what I am doing wrong or do you have a sample post of a grid to a webmethod??  I am using 2016.2 of the grid

Thanks,

  • 23953
    Offline posted

    Hello CodeGrunt,

    I'm attaching a sample that demonstrates how you can bind igGrid to WebMethod.

    There are few things to mention:

    1. Since you enabled Paging feature you'll need to return JSON in specific format. I created a GridJsonModel class to account for that. The WebMethod returns an object of this class.
    2. Again because of the Paging you need 2 params in your WebMethod: pageSize and pageIndex. Use those to slice the data.
    3. In igGrid configuration correctly setting "responseDataKey" and "recordCountKey" is important.

    Best regards,
    Martin Pavlov
    Infragistics, Inc.

    igGrid_WebMethod.zip