Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

javascript - dc.js - data table using jquery data-table plugin

I'm using dc.js to create charts and data table.

I wanted to add some pagination styles and search option in the table.

jQuery Data table script :

$(document).ready(function() {
    $('#data-table').DataTable();
})

problem is - i get all the jquery data table options displayed like search box, number of entries. But none of them work.

Some one please help.

Found this post. But nothing useful.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I like to use DynaTable for this - http://www.dynatable.com/

1) Define your table html:

<table id="dc-data-table">
    <thead>
      <tr>
        <th data-dynatable-column="client_name">Client</th>
        <th data-dynatable-column="project_name">Project</th>
      </tr>
    </thead>
 </table>

2) Hook in dynatable with your preferred options and the crossfilter dimension:

         var dynatable = $('#dc-data-table').dynatable({
                features: {
                    pushState: false
                },
                dataset: {
                    records: tableDimension.top(Infinity),
                    perPageDefault: 50,
                    perPageOptions: [50, 100, 200, 500, 1000, 2000, 5000 ,10000]
                }
            }).data('dynatable');

3) Write a method to refresh the table - dc.events helps to limit the number of times this is called on brush changes:

            function RefreshTable() {
                dc.events.trigger(function () {
                    dynatable.settings.dataset.originalRecords = tableDimension.top(Infinity);
                    dynatable.process();
                });
            };

4) hook this method into each charts filter event:

            for (var i = 0; i < dc.chartRegistry.list().length; i++) {
                var chartI = dc.chartRegistry.list()[i];
                chartI.on("filtered", RefreshTable);
            }

5) Call Refresh table once to display the current data:

            RefreshTable();

6) Render the DC charts:

            dc.renderAll();

Here is a jsfiddle for this: http://jsfiddle.net/djmartin_umich/5jweT/2/

Note that in this fiddle I used the group rather than the dimension to feed the dynatable data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...