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.
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
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!
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?
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()).
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!!
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.
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
...
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 );
} );
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
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.
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?? :)
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... :)
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 ;)
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.
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...
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!
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
Answers
It appears you haven't included the
sum()
plug-in that I linked to above on the page. Therefore there is nosum()
method and that is causing the issue.Adding it will allow the code to operate.
Allan
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
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
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!fnSettings
is the old API, so that isn't going to work. Usepage.info()
to get the paging info in the new API.In
footerCallback
you can usevar table = this.api()
to access the API.To calculate only the filtered rows, use
rows( { search: 'applied' } )
. See therows()
documentation for more.Allan
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?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
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!!
Hi,
Was just wondering if you have got my last message :)
Merry Xmas ;)
I don't understand I'm afraid.
search()
is the global search. You were usingcolumn().search()
before, so you would use:table.columns("."+ column).search('').draw();
or similar.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:
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
I don't understand this I'm afraid. I would need to be able to see the page to fully understand I think.
Use an initial value for
reduce
- e.g. modify thesum()
API method to be:I will update the plug-in as soon as I can.
Allan
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?
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
Problem there is where to stop. It would be great to have all of the plug-ins available when needed in the core...
column(".status").search('')
should remove the search.Allan
Hi Allan and happy new year to you and all datatables community :)
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('')
orcolumn(".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?? :)
I see - in which case, perhaps you should just do both?
Yes, I'll do that just now. Edit - I can't find a link in this thread... Where is it?
Allan
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?
haha, actually the icon disappears after 24h, u thought you had the power as admin to change it... :)
That won't effect the column filters.
What you could do is:
which will effect all columns (which might or might not be what you want).
I do :-). But I can't see the link in this thread to edit it. Where is it?
Allan
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 simplytable.search('');
My only question about it is if it will affect any speed performance searching the whole table instead of one specified column!!
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?
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
Hi, I have uploaded a test page: Link
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 :)
Got it - link now removed :-)
Sure - use column filters. There is only one global filter (unless you write a plug-in).
Allan
Thank you :)
OK, once again thanks for all, I wouldn't have made it without your precious help ;)
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 ;)
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
OK, thank you ;)
and happy belated new year ;)
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
Yes - your server is running out of memory :-). Either you need to increase PHP's allocation, or switch to server-side processing.
Allan
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?
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