I made some examples about multifiltering and column filtering for native php version of the library but it is very similar to this library.
you may wanna check these..
If you open the actual page you get the table, but it only shows “Processing…”.
Firebug shows me that the json code was loaded. Here is what I’m wondering: why is sEcho 0. Shouldn’t that be 1? If I manually change it to 1 the data is shown inside the table. If I understand it correctly, the value should get updatet everytime I update the table. Basically a draw count. So what is going wrong?
Another thing is: shouldn’t I only get the first 10 accounts, not all 14?
I’m working on this for far too long. Quite frustated right now :/
If anyone can help, I would appreciate it.
I pretty much followed this tutorial Ignited Datatables Tutorial on Vimeo
DiLer - I’m having the same exact problem. When I directly access my controller that produces the json I see the correct data output. I was also able to get it to work when I set bServerSide to false.
EDIT 2: I made two changes to get this to work.
First, set add “sServerMethod”: “POST” so your script looks something like:
I want to add a column by using add_column() function only under certain circumstances.
For example in a table with data, only if a user is the creator of the table’s row data to be able to edit it by showing a column like “Edit”, otherwise the column will be hidden or display nothing.
I want to add a column by using add_column() function only under certain circumstances.
For example in a table with data, only if a user is the creator of the table’s row data to be able to edit it by showing a column like “Edit”, otherwise the column will be hidden or display nothing.
And i would like the add_column to be added and shown only on certain rows based on a check that i will be doing if the user is the creator.
Is it possible somehow or do i have to edit the core of the datatables library?
OK i found a way, even if in my opinion is not the best one.
I am taking the output of the above function,
decoding using json_decode,
checking through other function for each desired json object ‘id’ if current user is its creator and if true then changing its ‘edit’ column value to the desired output,
then re-json_encode() and display the output.
DiLer - I’m having the same exact problem. When I directly access my controller that produces the json I see the correct data output. I was also able to get it to work when I set bServerSide to false.
EDIT 2: I made two changes to get this to work.
First, set add “sServerMethod”: “POST” so your script looks something like:
Oh man, thanks a lot!
At first it didn’t work, but I could figure out why. I enabled csrf protection in the config file. There is an issue with ajax and this option when set to TRUE.
$config['csrf_protection'] = TRUE;
The moment I disabled it, it worked. BUT I don’t want to disable it. So I googled for an hour or so and here is what I found:
So in the end I just changed the code as showed above and modified the datatables library as you mentionend.
I guess “sServerMethod”: “POST” and ajax(‘type’: ‘POST’) is pretty much the same?! That’s why I didn’t need it?!
Thanks again laxdoctor, you made my day (or year)
/edit
Ok the search does not work :/
Probably because of the modification of the datatables library…does anyone have a solution?
/edit2
Oh man I hope this is the right solution…
I found out that the sql queries are escaped wrong. Take a look at this:
SELECT `id`, `username`, `create_date` FROM (`accounts`) WHERE (id LIKE '%'somestring'%' OR username LIKE '%'somestring'%' OR create_date LIKE '%'somestring'%' ) ORDER BY `id` asc LIMIT 10
This is what datatables does. But as you can see ‘somestring’ (the word I searched for) shouldn’t have the ‘’ around it. The query should be ...LIKE ‘%somestring%’ .... and not ...LIKE ‘%‘somestring’%’...
With that in mind I changed the datatables library back to normal. So line 295 is
if($sSearch != '')
again.
But I changed line 290 (I tested a lot of stuff, so maybe it’s a line above or under that, I’m not 100% sure).
I want to add a column by using add_column() function only under certain circumstances.
For example in a table with data, only if a user is the creator of the table’s row data to be able to edit it by showing a column like “Edit”, otherwise the column will be hidden or display nothing.
And i would like the add_column to be added and shown only on certain rows based on a check that i will be doing if the user is the creator.
Is it possible somehow or do i have to edit the core of the datatables library?
OK i found a way, even if in my opinion is not the best one.
I am taking the output of the above function,
decoding using json_decode,
checking through other function for each desired json object ‘id’ if current user is its creator and if true then changing its ‘edit’ column value to the desired output,
then re-json_encode() and display the output.
I did rewrite one of my datatables view with mDataProp function for almost all columns using “aoColumns”. At the end I discovered that sorting a columns doesn’t work because Ignited Code is receiving ‘function’ for mDataProp. Is is possible to redefine that ‘function’ type by returning something from one of a few type of calls to mDataProp function?
I don’t like a solution with “aoColumnDefs” because I had to use “aTargets” with column numbers. mDataProp object approach is much better for my complicated and composed columns.
and then creat a view (raw_ajax.php in my example) with just
<?php echo $result; ?>
it should work a little better
have swing
Hey thanks a lot for your reply.
I tryied what you suggested but still nothing displays if i set bServerSide: TRUE
If i set it to FALSE , everything works ok.
I converted two “mDataProp” columns from functions to ones as field names. Now Ignited Code makes a query with their names (field1 & field2) as filters:
WHERE (field1 LIKE ‘%’‘%’ OR field2 LIKE ‘%’‘%’ )
As there is no filter values the query returns no records instead of returning all records!?
echo prints result on the page as follows:
{“sEcho”:0,“iTotalRecords”:2,“iTotalDisplayRecords”:2,“aaData”:[[“1”,“23096720”,“MIHIR”,“mihir.parekh@abc.com”,“1”],[“2”,“12345”,“Mihir”,“abc@gmail.com”,“1”]],“sColumns”:“id,username,name,email,login_count”}