Skip to content

Feature/server side datatables schools clean#425

Open
ronikriger wants to merge 7 commits intobeautyjoy:mainfrom
cs169:feature/server-side-datatables-schools-clean
Open

Feature/server side datatables schools clean#425
ronikriger wants to merge 7 commits intobeautyjoy:mainfrom
cs169:feature/server-side-datatables-schools-clean

Conversation

@ronikriger
Copy link
Copy Markdown
Contributor

What this PR does:

  • Added the ajax-datatables-rails gem and created a SchoolDatatable class that handles pagination, sorting, and server-side search across Name, City, State, Country, and Website columns.
  • Updated SchoolsController#index to respond with JSON (via SchoolDatatable) for AJAX requests and HTML for normal page loads.
  • Replaced the server-rendered <tbody> in the schools index view with a DataTables-managed table (#schools-table) that fetches data from the JSON endpoint.
  • Added a dedicated schools_index.js pack to initialize the table with serverSide: true, bound to both document.ready and turbolinks:load.
  • Grade Level, Teachers count, and the Actions column are display-only (not searchable/sortable).

Who authored this PR?

@ronikriger

How should this PR be tested?

  • Visit /schools and verify the table loads with paginated data
  • Use the search box to filter by school name, city, state, country, or website
  • Verify pagination controls work (next/previous, page size selector)
  • Confirm the merge-schools modal still functions as before
  • Run bundle exec rspec spec/controllers/schools_controller_spec.rb
  • Run bundle exec cucumber features/schools_datatable.feature

IMPORTANT FOR DEVELOPERS!!!

This PR puts a new gem ajax-datatables-rails to the Gemfile. After merging, all developers will need to run bundle install to pick up the new dependency.

@cycomachead @armandofox @mdawn65

ronikriger added 6 commits April 29, 2026 17:55
- Add ajax-datatables-rails gem
- Create SchoolDatatable class with view_columns and data methods
- Update SchoolsController#index to respond to JSON format
- Add request spec verifying DataTables JSON structure
- Add datatable_params helper for realistic DataTables request params
- Verify recordsTotal/recordsFiltered match school count
- Verify each record returns name, location, country, website,
  teachers_count, grade_level, and DT_RowId
Override filter_records in SchoolDatatable to include state in
global search (not covered by view_columns since Location is a
composite display column).
- Replace server-rendered rows with empty tbody for AJAX population
- Add id="schools-table" and data-source attribute for JS init
- Remove js-dataTable class so shared init doesn't interfere
- Remove @Schools assignment from HTML path (data comes via JSON)
- Update index spec to match new behavior
- Add schools_index.js with serverSide DataTables init on #schools-table
- Bind to both document.ready and turbolinks:load
- Return HTML links and action buttons from SchoolDatatable#data
- Mark HTML output as html_safe to prevent double-escaping
- Add Cucumber scenarios for page load and search behavior
- Update RSpec assertions for HTML-wrapped field values
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.32%. Comparing base (daa7e96) to head (adc178b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
+ Coverage   74.71%   75.32%   +0.60%     
==========================================
  Files          29       30       +1     
  Lines        1135     1163      +28     
==========================================
+ Hits          848      876      +28     
  Misses        287      287              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cycomachead
Copy link
Copy Markdown
Member

@ronikriger Can you resolve the linter issues?

@kienthuynh
Copy link
Copy Markdown
Contributor

@ronikriger Can you resolve the linter issues?

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants