Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load DataTables plugins with Vite?

I am able to successfully load DataTables on my element with Vite, however the rowgroup plugin is not loading. How do I do this?

import jQuery from 'jquery';
Object.assign(window, {
    $: jQuery,
    jQuery
})
import DataTable from 'datatables.net';
import 'datatables.net-rowgroup';
DataTable($);

let table = $("table").DataTable(options);

The error I receive is

table.rowGroup is not a function
like image 400
Antonio Gonzalez Avatar asked Apr 22 '26 00:04

Antonio Gonzalez


1 Answers

Here is an answer to make plugin work.

import jQuery from "jquery";
import $ from "jquery";

import DataTable from "datatables.net";
DataTable(window, $);

import RowGroup from "datatables.net-rowgroup/js/dataTables.rowGroup.min.js";
RowGroup(window, $);

Look at also my complete answer https://stackoverflow.com/a/74039112/10489562 to use datatable.net with Vite.

like image 68
phili_b Avatar answered Apr 23 '26 15:04

phili_b