简体   繁体   English

如何获得Kendo Grid ClientTemplate价值到Javascript

[英]How To Get Kendo Grid ClientTemplate Value To Javascript

Please find my Kendo Grid below 请在下面找到我的剑道网格

@(Html.Kendo().Grid(Model)
                    .Name("Grid")
                    .Columns(columns =>
                    {
                        columns.Bound(p => p.Callid).Title("CALL ID").Sortable(true).Width(80);        
                        columns.Bound(p => p.CallConnectTime).Title("CONNECTED TIME");
                        columns.Bound(p => p.CallTerminateTime).Title("TERMINATED TIME");
                        columns.Bound(p => p.Duration).Title("DURATION(Seconds)").Width(140);  
                        columns.Bound(p => p.AudioFileName).ClientTemplate("<input type='hidden'
         value='#=AudioFileName#'/> 
            <a href='javascript:void(0)' class='ui-btn-a ecbPlayClass'>
        <img src='" + Url.Content("~") + "img/play-circle-fill-32.png'
         height='20' width='20'/>"          



                          );        
                    })
                        .Pageable()
                             .Sortable()
                             .Groupable()
                             .Scrollable()
                             .Filterable()
                             .ColumnMenu()
                              .DataSource(dataSource => dataSource
                                 .Ajax()
                             .ServerOperation(false)
                             .Model(model => model.Id(p => p.Callid))
                             )
                         )

I am trying to call call a JavaScript mentioned below 我试图打电话给下面提到的JavaScript

    <script type="text/javascript">

        $(".ecbPlayClass").click(function (event) {
            var fPath = $(this).children().attr("#= AudioFileName #");           
            var tbl = $('#ECBPlayer');      

            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetEcbaudioPlay")',
                dataType: 'html',
                data: { AFilePath: fPath }
            }).success(function (result) {
                tbl.empty().append(result);
                $("#dialog").dialog();
            }).error(function () {

            });
        });

    </script>

where method mentioned in the JavaScript is JavaScript中提到的方法是什么

 public ActionResult GetEcbaudioPlay(string AFilePath)
        {
            string SimageBase64Data = string.Empty;
            try
            {
                //byte[] imageByteData = System.IO.File.ReadAllBytes(AFilePath);
                //SimageBase64Data = Convert.ToBase64String(imageByteData);
            }
            catch (Exception)
            {

            }
            return PartialView("_EcbAudioPlayer", AFilePath);
        }

All I want is to get the AudioFile value to the string parameter in the method GetEcbaudioPlay . 我想要的是将AudioFile值获取到方法GetEcbaudioPlay的字符串参数。 How can I get the value to that method?Please can anyone help me with this. 我怎样才能获得该方法的价值?请任何人都可以帮助我。 Or is there any alternative method to do this. 或者有没有其他方法可以做到这一点。

Thanks Shyam 谢谢Shyam

Ok if it was me I would probably tweak the code a little like this. 好吧,如果是我,我可能会调整代码有点像这样。

For your clientTemplate I would probably do this: 对于你的clientTemplate我可能会这样做:

columns.Bound(p => p.AudioFileName).ClientTemplate("#=showAudioButton(data.AudioFileName)#");

This will then call a javascript function that will then display a button/link for you. 然后,这将调用一个javascript函数,然后为您显示一个按钮/链接。

function showAudioButton(filename) {
    var retString = '';

    if (filename.length !== 0 && filename !== '' && filename !== undefined) {
        retString = '<button type="button" class="ui-btn-a ecbPlayClass" data-audio-filename="' + 
            filename +
            '">' +
            '<img src="@Url.Content("~/img/play-circle-fill-32.png")"  height="20" width="20"/>
              </button>';
    } else {
        retString = '<span>-</span>';
    }

    return retString;

}

This should then return back a button with the image if a file name is provided. 如果提供了文件名,则应该返回带有图像的按钮。

Then adding a DataBound event to the grid like this: 然后将DataBound事件添加到网格中,如下所示:

.Events(events => {events.DataBound("onDataBound");})

we can then attach the event handler to the items like so: 然后我们可以将事件处理程序附加到这样的项目:

function onDataBound(e) {
    var audioButtons = $('button[data-audio-filename]');
    if (audioButtons !== null && audioButtons.length > 0) {
        $('button[data-audio-filename]').on('click', function (me) {
            me.preventDefault();
            var myvalue = $(this).data("audio-filename");
            var tbl = $('#ECBPlayer');   

            //call your service url here.
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetEcbaudioPlay")',
                dataType: 'html',
                data: {
                    AFilePath: myvalue
                }
            }).success(function (result) {
                tbl.empty().append(result);
                $("#dialog").dialog();
            }).error(function () {

            });


        });
    }
}

I haven't tested this code but hopefully you can see what I am trying to achieve here for you. 我没有测试过这段代码,但希望你能看到我想为你实现的目标。

If you need more info let me know. 如果您需要更多信息,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM