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

[Solved] Dynamic templating

1 Answer 99 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.
Charley
Top achievements
Rank 1
Charley asked on 11 Aug 2011, 06:55 PM
I have this grid that is loaded from the server I update the grid via my own javascript function.  That works perfectly.  I grab the json object from the rest service and pass it to grid.dataBind property it works magnificently.  But once I added a .Template column on the dynamic update of the grid the stuff that is supposed to be inserted into that .Template column is not being re-inserted.  The below code is my current configuration.  I am still playing with some of the features this is why it is so loaded with stuff.  I have included the razor grid declaration as well as the javascript in question.  Thanks for the replies.

Html.Telerik().Grid((List<IMRS.Model.WorkOrderRepairLine>)ViewData["workOrderRepairLine"])
                    .Name("WorkOrderRepairLines")
                    .DataKeys(d => d.Add(o => o.ID))
                    .Columns(c =>
                    {
                        c.Bound(o => o.ID).Visible(false);
                        c.Bound(o => o.ConditionCodeId).Visible(false);
                        c.Bound(o => o.WorkOrderRepairLineStatusId).Title("S").ReadOnly().Width(20);
                        c.Bound(o => o.JobCodeDescription).Title("Description").Width(60);
                        c.Bound(o => o.UnitLocationCodeDescription).Title("Loc").Width(25);
                        c.Bound(o => o.WhyMadeCodeDescription).Title("Why Made").Width(46);
                        c.Bound(o => o.ConditionCodeDescription).Title("Con Code").Width(46);
                        c.Bound(o => o.DefectQuantity).Title("Def Qty").Width(40);
                        c.Bound(o => o.DefectSize).Title("Def Size").Width(50);
                        c.Bound(o => o.RepairQuantity).Title("Rep Qty").Width(50);
                        c.Bound(o => o.RepairSize).Title("Rep Size").Width(50);
                        c.Bound(o => o.ResposibilityCodeDescription).Title("Resp").Width(30);
                        c.Bound(o => o.J2ActivityID).Title("J2 Act").Width(50);
                        c.Bound(o => o.LaborAmount).Title("Labor").Width(51).Format("{0:c}");
                        c.Bound(o => o.MaterialAmount).Title("Matl").Width(50).Format("{0:c}");
                        c.Bound(o => o.TaxAmount).Title("Tax").Width(50).Format("{0:c}");
                        c.Bound(o => o.Authorize).Title("Auth").Width(30).ClientTemplate("<input type=\"checkbox\" disabled=\"disabled\" name=\"Authorize\" id=\"Authorize\" <#= Authorize? checked='checked' : '' #> />");
                        c.Command(commands => commands.Delete().ButtonType(GridButtonType.Image)).Width(25);
                        c.Template(@<text><span>test</span></text>);
                    })
                    .DataBinding(databinding =>
                        databinding.WebService()
                        .Update("http://imrs/workorder/UpdateWorkOrderJSON/")
                        .Select("http://imrs/workorder/UpdateWorkOrderJSON/")
                        .Insert("http://imrs/workorder/UpdateWorkOrderJSON/")
                        .Delete("http://imrs/workorder/UpdateWorkOrderJSON/")
                    )
                    .ToolBar(tools =>
                        {
                            tools.Insert().ButtonType(GridButtonType.Image);
                        }
                    )
                    .ClientEvents(events => events
                        .OnLoad("onDataBinding")
                        .OnEdit("editConditionCode")
                        .OnSave("anothertest")
                        .OnDelete("testdelete")
                        .OnDetailViewCollapse("onDetailViewCollapse")
                        .OnDetailViewExpand("onDetailViewExpand")
                        .OnDataBinding("onDataBinding2")
                        .OnRowDataBound("onRowDataBound")
                        .OnRowSelect("onRowSelect")
                        .OnDataBound("onDataBound")
                        .OnColumnResize("onColumnResize")
                        .OnColumnReorder("onColumnReorder")
                    )
                    .Selectable()
                    .KeyboardNavigation()
                    .Editable(
                        editable => editable.Mode(GridEditMode.InCell))
                )

JAVASCRIPT
var grid = null;
 
    function onDataBinding(result)
    {
        grid = $(this).data('tGrid');
    };
    function GetWorkOrder(id)
    {
        $.ajax({
            url: 'http://imrs/workorder/detailsjson/' + id + '',
            data: {},
            type: "GET",
            dataType: "json",
            jsonpCallback: "localJsonpCallback"
        });
        currentWorOrderID = id
    };
 
    function localJsonpCallback(json)
    {
        currentInvoice = json;
        grid.dataBind(json.WorkOrderRepairLines);  //  other stuff not important to question
    }


1 Answer, 1 is accepted

Sort by
0
Charley
Top achievements
Rank 1
answered on 18 Aug 2011, 06:32 PM
I found this out myself.  if you .ClientEvents(events => events.OnDataBound("somefunction").  Inside that function you traverse the table where you need to go (jquery has a nice set of methods to do this).  Then add the appropriate data to the column desired. 

Hope this helps some one else.


Regards

Charley
Tags
Grid
Asked by
Charley
Top achievements
Rank 1
Answers by
Charley
Top achievements
Rank 1
Share this question
or