loaded the jqgrid columns in xml and it is loaded correctly. Issue is on click of button, i need to call ajax json call and add rows to grid

Guhananth S 1 Reputation point
2022-01-08T06:37:18.853+00:00

Hi
Pricing.js
$(function(){
$('#btnGo').button().click(function () {
$.ajax({type:"Post",
url:'/Pricing/Values',
data:'json',
success:function(result){
var mydata=[]
below data is json string to be formed from controller call
for(var j=0;j<=data.length;i++)\
{
mydata[i] ={};
for (var j=0 ; j<data[i].length : j++)
{
mydata[i][names[j]] = data[i][j];
}
}
//Add to grid here
for(var i= 0 ;i<=mydata.length; i++)
{
$fn.activeGrid().jqGrid('addRowdata',i + 1,mydata[i]);
}
});
this is working fine with static json data. issue is getting json from controller
}
}

Controller i have
public JsonResult GetValues(string sidx,sting sord,int page,int rows){
List<Dictionary<string,object> strResult = new Dictionary<string,object>();
Search sp = new Search();
strResult = _service.GetData(sp);
var values = JsonConvert.DeseriaizeObject<Dictionary<string,object>>( strResult.toString());

return Json(values,JsonRequestBehaviour.AllowGet):

}

Developer technologies | ASP.NET | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    2022-01-10T09:18:43.417+00:00

    Hi @Guhananth S ,

    loaded the jqgrid columns in xml and it is loaded correctly

    You said it loaded correctly, what's the effect now?
    Add row to grid, do you want to add new data via button?
    If you want to get json from controller, you can refer to my post to reply you this Jq grid on button click,
    If you want to create new data you can use $("#grid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Guhananth S 1 Reputation point
    2022-01-10T10:34:39.817+00:00

    on click of button , i want to add jsonresult to be added to grid.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.