Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update fnFilter function

Signed-off-by: Sakchai Siripanyawuth <sakchai@artellectual.com>
  • Loading branch information...
commit 0a303b858c11569980b1abd68bdcc4717ac10231 1 parent 9848d0f
@zacksiri zacksiri authored
Showing with 80 additions and 0 deletions.
  1. +80 −0 vendor/assets/javascripts/simple_datatables.js.coffee
View
80 vendor/assets/javascripts/simple_datatables.js.coffee
@@ -0,0 +1,80 @@
+//= require jquery.dataTables
+//= require jquery.datatables.fnSetFilteringDelay
+//= require jquery.datatables.fnReloadAjax
+
+root = exports ? this
+
+root.simpleDatatables = ( sSource, aoData, fnCallback ) ->
+
+ columns = [];
+ searchcolumns = [];
+ sortcolumns = [];
+
+ sEcho = 1;
+ sSearch = "";
+ bRegex = false;
+ iDisplayStart = 0;
+ iDisplayLength = 0;
+ data = [];
+
+ $.each(aoData, (index, dataObj) ->
+ switch dataObj.name
+ when "sColumns"
+ columns = dataObj.value.split(",");
+ when "sEcho"
+ sEcho = dataObj.value;
+ when "sSearch"
+ sSearch = dataObj.value;
+ when "bRegex"
+ bRegex = dataObj.value;
+ when "iDisplayStart"
+ iDisplayStart = dataObj.value;
+ when "iDisplayLength"
+ iDisplayLength = dataObj.value;
+ when "iSortCol_0"
+ console.log("yobanarot!");
+ iSortCol = dataObj.value;
+ when "sSortDir_0"
+ sSortDir = dataObj.value;
+ else
+ console.log(dataObj.name);
+ );
+
+ $.each(aoData, (index, dataObj) ->
+ search_regexp = ///sSearch_([0-9]+)///
+ if (col = dataObj.name.match(search_regexp)) and dataObj.value
+ console.log dataObj
+ data.push({name: "search["+columns[col[1]]+"]", value: dataObj.value});
+
+ search_regexp = ///bSearchable_([0-9]+)///
+ if (col = dataObj.name.match(search_regexp)) and dataObj.value
+ searchcolumns.push(columns[col[1]]);
+
+ search_regexp = ///iSortCol_([0-9]+)///
+ if (col = dataObj.name.match(search_regexp))
+ sortcolumns[parseInt(col[1])]=columns[parseInt(dataObj.value)];
+
+ search_regexp = ///sSortDir_([0-9]+)///
+ if (col = dataObj.name.match(search_regexp)) and dataObj.value
+ sortcolumns[col[1]]=sortcolumns[col[1]]+"."+dataObj.value;
+
+ );
+
+ data.push({name: "sEcho", value: sEcho});
+ data.push({name: "page", value: iDisplayStart/iDisplayLength + 1});
+ data.push({name: "per_page", value: iDisplayLength});
+ data.push({name: "search[meta_sort]", value: sortcolumns[0]});
+
+ $.each(columns, (index, val) ->
+ data.push({name: "columns["+index+"]", value: val});
+ );
+
+ if sSearch
+ op =
+ if bRegex
+ "_contains"
+ else
+ "_sw"
+ data.push({name: "search["+searchcolumns.join("_or_")+op+"]", value: sSearch});
+
+ $.ajax( { "dataType": 'json', "type": "GET", "url": sSource, "data": data, "success": fnCallback } );
Please sign in to comment.
Something went wrong with that request. Please try again.