jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
586 stars 228 forks source link

Render time is too slow and not orderable column still orderable #256

Closed HaiUIT-zz closed 6 years ago

HaiUIT-zz commented 6 years ago

I'm following the guide in readme file, everything work well exclude 2 a problem :

  1. Render time seem too slow, my data is only 6 rows but it take about 20k ms to render, base on server output, database query is pretty quick

    Started GET "/books.json?draw=1&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsear ch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=title&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Bordera ble%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=author&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchab le%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=first_published&columns% 5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&order% 5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1506397351782" for 127.0.0.1 at 2017-09-26 10:42:32 +0700 Processing by BooksController#index as JSON Parameters: {"draw"=>"1", "columns"=>{"0"=>{"data"=>"id", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "1"=>{"data"=>"titl e", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}}, "2"=>{"data"=>"author", "name"=>"", "searchable"=>"true", "orderable"=>"tru e", "search"=>{"value"=>"", "regex"=>"false"}}, "3"=>{"data"=>"first_published", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}} }, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"10", "search"=>{"value"=>"", "regex"=>"false"}, "_"=>"1506397351782"} (9.0ms) SELECT COUNT(*) FROM "books" CACHE (0.2ms) SELECT COUNT(*) FROM "books" Book Load (6.3ms) SELECT "books".* FROM "books" ORDER BY books.id ASC LIMIT $1 OFFSET $2 [["LIMIT", 10], ["OFFSET", 0]] Completed 200 OK in 102ms (Views: 86.4ms | ActiveRecord: 15.5ms)

but the xhr request takes 20k ms to complete captureissue Tested on both development and production environment.

2. When I set a column orderable to false in rb file, the sorting icon still show in view and when i click it, the table will be sorted. Base on server output above, my setting seem not to be applied. It seem like this feature has not implemented yet.

Everybody can check my code here :

ajahongir commented 6 years ago
  1. sorting you have to turn off on client side - look datatables.net config options for more details.
HaiUIT-zz commented 6 years ago

@ajahongir I have just checked the readme and updated my post.

For the first issue, it is not becuase ajax-datatables-rails or my code in server side render json slow, it is because of extremely slow in sending back json to browser. I'm still research to fix this new problem.