Combine selector-modifier with a function

Combine selector-modifier with a function

th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

The following code works, but only returns the first page. I would like to combine the modifier selector { "page" : "all" } but can't seem to figure it out. Any help would be appreciated.

The code selects rows with checkbox checked. but only returns current page. I'd like to return all pages hidden or not.

    var rowcollection = oTable
        .rows(function (idx, data, node) {

            return $(node).find($(".asin-check")).is(':checked') ? true : false;
        })
        .data();

This question has an accepted answers - jump to answer

Answers

  • th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

    anyone?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    The page: 'all' option is the default, which suggests to me that you are using server-side processing (although its impossible to say without more information). If you are using server-side processing, this it is working as expected since this is a client-side function and only the data for the current page is available at the client side. If you are not using server-side processing, please link to a test case showing the issue.

    Allan

  • th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

    Hi Allan, thanks for your reply.

    I am not using server side processing. I am using Ajax pulling Json from a .NET Web API

    Data is populating fine. The only checked rows being picked up are on the current page, regardless of page number

    Here is my table code. fairly vanilla. "I think?"

    var ajaxOptions = {
    url: "http://mydomain.com/api/my-method",
    type: "POST",
    data: jsonObject,
    contentType: 'application/json'
    

    }

    $('#my-table').DataTable({
        ajax: {
            url: ajaxOptions.url,
            type: ajaxOptions.type,
            data: function () {
                if (ajaxOptions.data == null)
                    return null;
                else
                    return JSON.stringify(ajaxOptions.data);
            },
            contentType: ajaxOptions.contentType
        },
        dom: 'T<"clear">lfrtip',
        tableTools: {
            "sSwfPath": "/assets/plugins/DataTables/swf/copy_csv_xls_pdf.swf"
        },
        "columns": [
            {
                data: "c1",
                render: function (data, type, full) {
                    return '<a href="' + full["somevalue"] + '" target="blank" >' + data + '</a>';
    
                },
            },
            {
                data: "c2",
                render: function (data, type, full) {
                    return '<a href="' + full["somevalue"] + '" target="blank" >' + data + '</a>';
    
                },
            },
    
            {
                data: "c3",
                render: function (data, type, row) {
                    return '<img src="' + data + '" alt="">';
    
                },
            },
        { "data": "c4" },
            {
                data: "c5",
                render: function (data, type, full) {
                    return '<a href="#" data-type="text" >' + data + '</a>';
    
                },
            }
        ],
        "initComplete": function (oSettings) {
    
        }
    });
    
  • th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

    Forgot to mention. Using DataTables version 1.10.4

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    It would be worth updating to the current release and trying that, but I ca#n't recall any bugs that would cause this.

    Can you link to a test case showing the issue so I can debug it please.

    Allan

  • th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

    Thanks again for your help. I found the offending line of code. By removing it, I was able to return all rows. I am going to play with it.

    // no workie
    return $(node).find($(".asin-check")).is(':checked') ? true : false;
    

    and here it is in context.

        var rowcollection = oTable
            .rows(function (idx, data, node) {
    
                return $(node).find($(".asin-check")).is(':checked') ? true : false;
            })
            .data();
    

    Maybe someone can spot the problem straight away.

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    $(".asin-check")

    this is selected from the document only - i.e. the visible rows, since jQuery knows nothing about DataTables' hidden rows.

    Can you simply use:

    .find(".asin-check")
    

    Allan

  • th3monk3yth3monk3y Posts: 6Questions: 1Answers: 0

    oh man! I can't believe I didn't see that! Blaring when you know what it is.

    Thanks Allan, problem solved!

This discussion has been closed.