Code Monkey home page Code Monkey logo

elastic-datatables's Introduction

HELP REQUIRED

I have no more time to maintain (and finish) this plugin. Any help will be welcome!


Elastic Datatables

When dealing with DataTables and ElasticSearch, one can quickly think about two things:

  • By its ability to return almost instantaneously a set of result and the total amount of matching results, ElasticSearch is a perfect fit for server-side processing
  • But ElasticSearch is a search engine, not a server in which we can code as we want.

So we can't simply give an ElasticSearch request to DataTables ajax config and hope for the pagination/filter/sort to be handled automagically. We can't modify the server code so we need to fake the system. We need to develop the server-side magic on client-side.

DataTables allow us to override the fnServerData function to have access to the internal state of our datatable before sending a request, which allows us to add the pagination/filter/sort information to the ElasticSearch request. See here for more informations.

The fact is that in every case, the same code will be used for that. The DataTable parameters (i.e. aoData.length: the number of row to display) will always be used the same way to construct the ElasticSearch request (i.e. { size: aoData.length }). This is a door for automation, and this plug-in is made for it.

TL;DR

Focus on your ElasticSearch request. Let this plug-in handle the pagination, filters and sorting of your DataTables.

Getting Started

Download the production version or the development version.

In your web page:

<script src="jquery.js"></script>
<script src="jquery.dataTables.min.js"></script>
<script src="elasticsearch.js"></script>
<script src="dist/jquery.elastic-datatables.min.js"></script>
<script>
var client = elasticsearch.Client({
  host: 'localhost:9200'
});

$('#example').dataTable( {
    'columns': [
        { 'sTitle': 'First name', 'sName': 'firstname' },
        { 'sTitle': 'Last name', 'sName': 'lastname' }
    ],
    'bProcessing': true,
    'bServerSide': true,
    'fnServerData': $.fn.dataTable.elastic_datatables( {
      index: 'test',
      type: 'test',
      client: client,
      body: {
        query: {
          match: {
            title: 'test'
          }
        }
      }
    } )
} );
</script>

Documentation

(Coming soon)

Release History

(Nothing yet)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.