cannot get child row when responsive

cannot get child row when responsive

jiawei016jiawei016 Posts: 1Questions: 0Answers: 0
edited May 23 in Free community support

when datatable is in window size _xTableItem.row(RowIndex).data() can get data in console but when datatable is in responsive the _xTableItem.row(RowIndex).data() get undefined value. i does not know what causes it, please help.

    $(document).ready(function () {
        var _dataresult = {
            xError: "0",
            xErrorMessage: [],
            xItemRecords: [{
                xItemDescription: "this is item a",
                xItemId: "IM1",
                xItemName: "item a",
                xItemPrice: 0
            }],
            xResult: "1"
        };

        var _xTableItem = $('table[data-role="xTableItem"]').DataTable({
            select: true,
            scrollY: 550,
            scrollCollapse: true,
            autoWidth: false,
            responsive: true,
            processing: true,
            retrieve: true,
            pageLength: 5,
            pagingType: 'listbox',
            buttons: [],
            data: _dataresult.xItemRecords,
            rowId: 'xItemId',
            responsive: {
                details: {
                    display: $.fn.dataTable.Responsive.display.childRowImmediate,
                    type: 'column',
                    target: '.expandable'
                },
                breakpoints: [
                    { name: 'desktop', width: Infinity },
                    { name: 'tablet', width: 1024 },
                    { name: 'fablet', width: 768 },
                    { name: 'phone', width: 480 }
                ]
            },
            language: {
                emptyTable: "No Records"
            },
            columnDefs: [],
            select: {
                style: 'multi',
                selector: 'td:first-child'
            },
            columns: [
                { data: null, defaultContent: '', className: 'select-checkbox table-control', orderable: false },
                { data: null, className: 'control expandable table-control', orderable: false, defaultContent: "", searchable: false },
                { "data": "xItemId", "title": "Id", className: "never" },
                { "data": "xItemName", "title": "Item Name ", className: "all expandable" },
                { "data": "xItemPrice", "title": "Price ", className: "desktop" },
                { "data": "xItemDescription", "title": "Description", className: "desktop" },
                { "data": null, "title": "Action", className: "desktop", "defaultContent": "<button class='btn-primary btn-block btn btn-xs' data-role='btn_ViewAction'>View</button>", "targets": -1 }
            ],
            dom: '<"row"<"col-md-12"f>>t<"row col-md-12 pull-left mt-2"l>i',
            order: [[2, 'asc']]
        });

        $('table[data-role="xTableItem"]').on('click', 'button[data-role="btn_ViewAction"]', function () {
            //Method 1
            var RowIndex = $(this).closest('tr');
            var data = _xTableItem.row(RowIndex).data();
            console.log(data);

            //Method 2
            var tr = $(this).closest('tr');
            var row = _xTableItem.row(tr);
            console.log(row.data());
        });
    });

Replies

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.