What is the limit of records we can deal with? - Page 3

What is the limit of records we can deal with?

13

Answers

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

    It appears you haven't included the sum() plug-in that I linked to above on the page. Therefore there is no sum() method and that is causing the issue.

    Adding it will allow the code to operate.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    awchh! sorry, i thought sum() was already included in the datatables.js file!!
    I have added the sum() js code but still have an error, you can check it in the same page

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

    As you are Ajax loading the data, you need to do it in initComplete. Otherwise there is no data in the table when it runs...

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    great, it works well inside "initComplete", but is possible to use sum() only after filtering? because the initial sum is calculated and displayed using an SQL query. I tried to do it in "footerCallback" but i get an error: "Uncaught TypeError: Cannot read property 'rows' of undefined"

    I'll also need to calculate the average order price, so how can I get the number of total retuned rows? I tried with table.fnSettings().fnRecordsTotal() but didn't work!

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

    fnSettings is the old API, so that isn't going to work. Use page.info() to get the paging info in the new API.

    In footerCallback you can use var table = this.api() to access the API.

    To calculate only the filtered rows, use rows( { search: 'applied' } ). See the rows() documentation for more.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited December 2014

    Thank you for your reply.

    One other thing please: I build a custom filter with buttons and i use table.columns("."+ column).search(val).draw(); it works perfectly, but when i click on the button "All records", i'll need to reset the search, didn't find any info regarding this in the doc... how can this be done?

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

    You would simply call the search function again with the val being an empty string. If you need to modify the content of an input, you would use standard jQuery or DOM actions (such as $().val()).

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    I actually have tried it but didn't work:
    table.search("").draw();
    in my case i can not use .columns() because i'm cancelling the previous search and can't mention any column!!

  • redaniredani Posts: 70Questions: 1Answers: 0

    Hi,

    Was just wondering if you have got my last message :)

    Merry Xmas ;)

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

    I don't understand I'm afraid. search() is the global search. You were using column().search() before, so you would use: table.columns("."+ column).search('').draw(); or similar.

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited December 2014

    Hi,

    Yes, i was using column(".column_class").search(search_val); but when i want to cancel the search, i click on a button but i wont be able to use column(".column_class").search(''); because i can't tell which column_class has been used first... except if i declare its variable as a global one!!
    I guess the solution would be to use only search() without mentioning the column(".column_class"), right?

    There is one last thing, I'm using the following code:

    var table = $(".datatable").DataTable({ 
        ...,
        "footerCallback": function(row, data, start, end, display) {
            var api = this.api();
                        
            if(api.column(1).data().length) { // wait until datatables renders
                var num_rows = api.page.info().recordsDisplay;
                var total = api.rows({ search: "applied" }).data().pluck("toteur").sum();
            }
            else {
                num_rows = total = 0;
            }
            
            $("h1 span.num").html(num_rows);
            $("#extra span.total").html(total);
    });
    

    everething works perfectly, but when i'm entering for example "test" in the search box, it will display all rows containing "test", but if then i enter "testx", it gets an error in stead of displaying "no results". Here is a portion of the error:
    Uncaught TypeError: Reduce of empty array with no initial value
    (anonymous function)
    $.DataTable.footerCallback
    ...

    do you know how i can fix this?

    Thanks a lot for all

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

    because i can't tell which column_class has been used first... except if i declare its variable as a global one!!

    I don't understand this I'm afraid. I would need to be able to see the page to fully understand I think.

    Uncaught TypeError: Reduce of empty array with no initial value (anonymous function) $.DataTable.footerCallback ...

    Use an initial value for reduce - e.g. modify the sum() API method to be:

    jQuery.fn.dataTable.Api.register( 'sum()', function () {
        return this.flatten().reduce( function ( a, b ) {
            return (a*1) + (b*1); // cast values in-case they are strings
        }, 0 );
    } );
    

    I will update the plug-in as soon as I can.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited January 2015

    Hi,
    I have uploaded a test page: [removed]

    Regarding the search() what i was talking about is that if you click on "Filter" then "Shipped", it will search in ".status" column (column(".status").search(search_val)), but then if you click on "All Orders", how would you cancel the search?

    Use an initial value for reduceDT - e.g. modify the sum() API method to be:

    Ohhh, you're a genius :) the problem is fixed :) Thank you so much :)
    It would be great if the sum() API could be integrated to the main datatables.js file

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

    It would be great if the sum() API could be integrated to the main datatables.js file

    Problem there is where to stop. It would be great to have all of the plug-ins available when needed in the core...

    Regarding the search() what i was talking about is that if you click on "Filter" then "Shipped", it will search in ".status" column (column(".status").search(search_val)), but then if you click on "All Orders", how would you cancel the search?

    column(".status").search('') should remove the search.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    Hi Allan and happy new year to you and all datatables community :)

    column(".status").search('') should remove the search

    haha, i think i still haven't made myself very clear :)
    when you click on "shipped", it'll search in ".status" column, but when you click for example on "PayPal", it'll search in ".payment" column! so when i want to cancel the search, i can't tell if i should do so using column(".status").search('') or column(".payment").search('') ! i hope you understand me better :)
    the solution us maybe simple: i should maybe use only .search(search_val) without specifying the column, but will that affect any speed performance??

    Have a good day

    P.S. will that be possible that you remove please the link i gave you in the previous post to prevent it from being crawled by google bots?? :)

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin
    edited January 2015

    I see - in which case, perhaps you should just do both?

    table.column(".status").search('');
    table.column(".payment").search('');
    

    P.S. will that be possible that you remove please the link i gave you in the previous post to prevent it from being crawled by google bots?? :)

    Yes, I'll do that just now. Edit - I can't find a link in this thread... Where is it?

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    I see - in which case, perhaps you should just do both?

    I thought about it but it might not be evolutive in the case i'll add more search columns... what if i use search() without specifying any column? will that affect speed performance?

    Yes, I'll do that just now. Edit - I can't find a link in this thread... Where is it?

    haha, actually the icon disappears after 24h, u thought you had the power as admin to change it... :)

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

    what if i use search() without specifying any column?

    That won't effect the column filters.

    What you could do is:

    table.columns().search('');
    

    which will effect all columns (which might or might not be what you want).

    haha, actually the icon disappears after 24h, u thought you had the power as admin to change it... :)

    I do :-). But I can't see the link in this thread to edit it. Where is it?

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited January 2015

    What you could do is: table.columns().search('');

    I actually already tried it but it doesn't cancel the search!!

    I think i will just as i said use table.search(search_val); so I can easily cancel the search using simply table.search('');
    My only question about it is if it will affect any speed performance searching the whole table instead of one specified column!!

    I do :-). But I can't see the link in this thread to edit it. Where is it?

    Well it disappears after 24h, it's normally in the top right of any posts...
    It's okay, do not bother ;)

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

    Well it disappears after 24h, it's normally in the top right of any posts... It's okay, do not bother ;)

    I know how to delete the link. But I can't find the link that you posted! Can you give me some of the text from your message with that link so I can remove it?

    My only question about it is if it will affect any speed performance searching the whole table instead of one specified column!!

    There will be a performance hit of course since there is more data to search. The best way to see fi it is acceptable for you, is to try it.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited January 2015

    Can you give me some of the text from your message with that link so I can remove it?

    Hi, I have uploaded a test page: Link

    The best way to see fi it is acceptable for you, is to try it.

    I tried it and it's stil very very very fast. I'm just admiring your work and how easy it's to use :) thanks again ;)

    I have another question :)
    I don't know if you remember the filter content, i had date, payment methods within a UL list, and order status within another UL list.
    will it be possible to cross the search ? for example display "all orders payed by card and declined" that means i'll have to select 1 option from each UL list...

    Thank you :)

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

    Got it - link now removed :-)

    that means i'll have to select 1 option from each UL list...

    Sure - use column filters. There is only one global filter (unless you write a plug-in).

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    Got it - link now removed :-)

    Thank you :)

    Sure - use column filters

    OK, once again thanks for all, I wouldn't have made it without your precious help ;)

  • redaniredani Posts: 70Questions: 1Answers: 0

    Hi Allan, how are you? :)

    I would love to ask you one question please, do you know a good jquery plugin that converts datatables into chart and graphs?

    Thanks ;)

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

    I don't know about one that "converts DataTables" since they all use their own data format, but you might want to look into HighCharts, or simply Google for Javascript charts. There are loads of them!

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    OK, thank you ;)
    and happy belated new year ;)

  • redaniredani Posts: 70Questions: 1Answers: 0
    edited January 2015

    Hi Allan,
    sorry to bother you again.
    Since this morning I have this error message that gets displayed: "DataTables warning: table id=DataTables_Table_0 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"

    and the json response is: "<b>Fatal error</b>: Out of memory (allocated 25165824) (tried to allocate 8506125 bytes) in ..."

    Do you know what that may be?

    The json response is Gziped, contains about 5000 records, the original size is 7Mb compressed to 305Kb

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

    Yes - your server is running out of memory :-). Either you need to increase PHP's allocation, or switch to server-side processing.

    Allan

  • redaniredani Posts: 70Questions: 1Answers: 0

    Thanks for the very fast reply :)
    wow, i can't believe i spent so many days to finish the implementation and already have to change everything :/

    Is there anything i should take into consideration to easily switch to server-side without any hassle?

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

    If you are using the Editor PHP libraries, all you need to do is enable the serverSide option and make an Ajax POST request. Example.

    Allan

This discussion has been closed.