How to initialize controls in row details with jQuery DataTables and Responsive extension

烈酒焚心 提交于 2019-12-02 03:56:32

CAUSE

This issue occurs because Responsive extension creates new elements when preparing row details. These new elements need to be initialized again.

SOLUTION

You need to re-initialize those controls that become part of row details in a separate function.

The solution is to:

  • define a custom render for the row details with responsive.details.renderer option
  • call default renderer with $.fn.DataTable.Responsive.defaults.details.renderer() which returns jQuery collection.
  • initialize custom controls in this collection before returning it.

Example:

var table = $('#example').DataTable({
    responsive: {
        details: {
            renderer: function (api, rowIdx, columns) {
               var $details = $.fn.DataTable.Responsive.defaults.details.renderer(api, rowIdx, columns);
                $(".numerictextbox", $details).kendoNumericTextBox({ format: "c", decimals: 2 });
                return $details;                    
            }
        }
    },
    createdRow: function( row, data, dataIndex ){
       $(".numerictextbox", row).kendoNumericTextBox({ format: "c", decimals: 2 });    
    }
});

DEMO

See this jsFiddle for code and demonstration.

LINKS

See jQuery DataTables – Responsive extension and custom controls article for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!