This is a migrated thread and some comments may be shown as answers.

[Solved] .ClientTemplate calling a $.get call

3 Answers 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon Baron
Top achievements
Rank 1
Jon Baron asked on 19 Sep 2012, 06:52 PM
So,

What I'm trying to accomplish is a normalized grid. That is, I have an ID column (bound to a grid column) and I'd like to display the proper textual value. I was hoping to do it in the bind expression but that doesn't seem to work.

So instead I'm trying to call a $.get call, everything works. I can even call an alert(data); to see that my call came back, and found the record I wanted.

However it looks like the grid renders before the call completes. As the value of the return value out of the javascript function is the initial value given to the return variable.

Help please?

3 Answers, 1 is accepted

Sort by
0
Jon Baron
Top achievements
Rank 1
answered on 19 Sep 2012, 07:54 PM
One thing to note:

function onRowDataBound(e) {
        var row = e.row; var dataItem = e.dataItem;
        $.get("/1/_2", { id1: dataItem.id1}, function (data) {
            row.cells[4].innerHTML = data;
        });
        $.get("/1/_3", { id2: dataItem.id2}, function (data) {
            row.cells[5].innerHTML = data;
        });
    }

Works. But my ID's which I would like to protect flash real fast before they're replaced with the text value. I would say this is not a good final solution.

Also, it crashes when a new Item is loaded into the Grid
0
Jon Baron
Top achievements
Rank 1
answered on 20 Sep 2012, 02:16 PM
Update,

This works for the flashing IDs:

 function onDataBound(e) {
               $("#gdi tbody tr").each(function () {            
            var tr = this;
            var cells = tr.cells;
            $.get("/1/_2", { id1: cells[4].innerHTML }, function (data) {
                cells[4].innerHTML = data;
            });
            $.get("/1/_3", { id2: cells[5].innerHTML }, function (data) {
                cells[5].innerHTML = data;
            });
        });

however, this also crashes when a new Item is added to the grid.

Could really use some help from the team on how to utilize the ClientTemplate approach.
0
Jon Baron
Top achievements
Rank 1
answered on 20 Sep 2012, 07:39 PM
Good news, looks like changing the ClientTemplate to:

var output = "";
        $.ajax({
            type: "get",
            async: false,
            url: "/controller/_Action",
            data: { Id: e }
        }).done(function (out) {
            output = out;
        });
        return output;
fixes it
Tags
Grid
Asked by
Jon Baron
Top achievements
Rank 1
Answers by
Jon Baron
Top achievements
Rank 1
Share this question
or