1

I see there are lot of related question in this site. But Still I am not able to make this work for my requirement.

This is my ajax call

 $.ajax({
      type: "POST",
      url: "/Medication/StopMedication",
      data: { ID: pid, StopNote: note },
      dataType: "json",
      success: function () {
           refreshGrid()
      }
});

and my refresh grid is like this

  function refreshGrid() {
        alert("I am at Refresh Grid");
        if ($(".t-grid .t-refresh").exists()) {
            $(".t-grid .t-refresh").trigger('click');
        }
    }

First of all after success my ajax call is not firing refreshGrid() function. can any one help me with this

I found the issue and fixed it:


I Made these Changes

 dataType: "text",
  success: function (data) {
       refreshGrid();
  }

 function refreshGrid() {
   $(".t-grid .t-refresh").trigger('click');
}

5 Answers 5

4

to reload the grid use this after success ajax call

var optionsGrid = $("#favorite-grid"); //you grid ID

optionsGrid.data('tGrid').ajaxRequest();

enjoy

Sign up to request clarification or add additional context in comments.

Comments

0

You need to troubleshoot first why the success callback is not invoked. Perhaps there is an error. You can try handling the error of $.ajax to see what the response is. You can also use some HTTP sniffing tool (WebKit's developer tools, FireBug or Fiddler) to inspect what the server response is.

When you sort out the success handler not being invoked you can use the ajaxRequest method of the grid to refresh it.

1 Comment

I could fix my problem. please check the solution i have updated on top
0
function refreshGrid() {
        $(".t-grid .t-refresh").trigger('click');
   }

This worked or me

Comments

0

In this way

   function refreshGrid() {
        $(".t-grid .t-refresh").trigger('click');
   }

it would refresh all of your grids on your page, if you have more than one grid. Even the detail grids will be refreshed.

To prevent this you can use the Id of your grid

@(Html.Telerik().Grid(Model)
    .Name("myGrid")
    .Columns(columns =>
    {
        columns.Bound(o => o.OrderID).Width(100);
        columns.Bound(o => o.ContactName).Width(200);
        columns.Bound(o => o.ShipAddress);
        columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
    })
..........
..........
..........
)

   function refreshGrid() {
        $("myGrid .t-grid .t-refresh").trigger('click');
   }

3 Comments

that's true, in my case i am having only one grid in a page and I use this refreshGrid() as a generalized function to call it when ever i need to refresh.
In this case you can pass a parameter function refreshGrid(myGrid) { $("#" + myGrid + " .t-grid .t-refresh").trigger('click'); }
Good. definitely Much Better way
0

For Server Bindings Telerik Grid Just need to do the following Thing..... Just use and cheers

After any event you can call this

 var href = $('.t-refresh').attr('href');
 window.location.href = href;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.