How to use the LIKE operator in Sheetrock

I am trying to call the javascript elem variable after LIKE in an SQL statement so that the input text is used there. However, the way I do this does not work with the Sheetrock library that I use ( http://chriszarate.imtqy.com/sheetrock/ ).

<!DOCTYPE html> <html> <body> Enter Tracking Code: <input type="text" id="textbox_id"> <input type="button" value="Submit"> <table id="switch-hitters" class="table table-condensed table-striped"></table> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.0.1/dist/sheetrock.min.js"></script> <script> var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0'; var elem = document.getElementById('textbox_id').value; $('#switch-hitters').sheetrock({ url: mySpreadsheet, query: "select A,B,C,D,E where A LIKE %"+elem+"%" }); </script> </body> </html> 
+5
source share
1 answer

Since you updated your question, there is an updated answer here. Check jsfiddle work: https://jsfiddle.net/r0sk7vtf/

  • you need to handle the submit button click event and then call the service

  • while the api table is understood as without quotes, it does not work through sheetrock.js, so you need to use A like '9999%' in your query

Excerpt:

 var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0'; var button = $('#btn'), elem = $('#textbox_id') button.on('click', function(e){ var v = elem.val(); $('#switch-hitters').sheetrock({ url: mySpreadsheet, query: "select A,B,C,D,E where A like '" + v + "%'" }); }) 
+3
source

Source: https://habr.com/ru/post/1244509/


All Articles