Pre-load a Query

To load a predefinded filter, you need to pass its JCSDL definition to the Query Builder and execute the loadJCSDL function with the query as a parameter. You can do this in several ways:

  • Provide a text area into which a user can paste the JCSDL definition of a query.
  • Hard code a JCSDL definition in your HTML code.
  • Retrieve a JCSDL definition through an AJAX call (for example, from a database).

The following example shows how you can pre-load a hard-coded JCSDL query in the Query Builder.


This code produces this result.

<div id="jcsdl"></div>

<textarea id="jcsdl-code" style="width: 900px; height: 200px;" disabled="true">// JCSDL_MASTER b04591342ee71a2baa468d9d2a340ec8 AND
// JCSDL_START 0980a5f2ef935c4ed153bf975879eac0 twitter.text,contains_any,27-52
twitter.text contains_any "obama, santorum, gingrich, romney, ronpaul, ron paul"
// JCSDL_START f7c18a6fedd90c6b4d77acc14a3a8e5c interaction.type,in,21-29
interaction.type in "twitter,facebook,youtube"
// JCSDL_MASTER_END</textarea>

<script type="text/javascript">
  var editor = new JCSDLGui('#jcsdl', {
    save : function( code ) {
    // perform custom saving of the output code
    // for example sending it in AJAX

    var code = $('#jcsdl-code').val();
    editor.loadJCSDL( code );