{"id":9,"date":"2007-05-11T14:29:14","date_gmt":"2007-05-11T11:29:14","guid":{"rendered":"http:\/\/www.trirand.com\/blog\/?p=9"},"modified":"2011-04-12T21:04:28","modified_gmt":"2011-04-12T18:04:28","slug":"searchdb-plugin","status":"publish","type":"post","link":"http:\/\/www.trirand.com\/blog\/?p=9","title":{"rendered":"Searchdb Plugin"},"content":{"rendered":"<p><strong>Searchdb<\/strong> is another jQuery plugin. The reason to write this plugin is that I&#8217;m a little be &#8220;lazy&#8221;. Imagine that you have a dynamic table (grid) or report in wich the user will search on many fields with diffrent criteria (equal, less, greater &#8230;). Constructing a form is a first problem. You must write so many tags and html code. The second and more importand problem is that I must analyze too much data passed to the server and construct it in a apropriate way in the WHERE clause of the SELECT statement.  So, I think &#8211; will be possible to pass only one parameter (the search criteria) , which can be directly passed in the WHERE clause? My answer after little thik was &#8211; yes this can be done.<br \/>\n<!--more--><br \/>\nI use again the best JS library<a href=\"http:\/\/jquery.com\"> jQuery<\/a> &#8211; remember the logo of jQuery &#8211; &#8220;Write less, do more&#8221;. Below is a little guide:<\/p>\n<p>This plugin creates a form of type condition &#8211; field value and return a string with a ready to use WHERE clause. Example: &#8220;name like &#8216;tony%&#8217; and rating &gt;= 1&#8243;.<\/p>\n<p>As usual the function can be placed in the document ready function to any html element.<\/p>\n<p>$(&#8216;#search1&#8242;).searchdb({searchModel: [<br \/>\n{label:&#8217;Title&#8217;,dbname:&#8217;message_title&#8217;,defval:&#8221;&#8221;, dtype:&#8221;S&#8221;, dopt:&#8221;cn;eq;lt;le;gt;ge;bw;ew&#8221;},<br \/>\n{label:&#8217;Autor&#8217;,dbname: &#8216;author&#8217;, dtype:&#8221;S&#8221;}<br \/>\n],<br \/>\ncapition: &#8220;Search Data Where&#8221;,<br \/>\nhideonSearch: false,<br \/>\ndisableClose: false,<br \/>\nonSearch: function(s) {<br \/>\nalert(s);<br \/>\n}<br \/>\n});<\/p>\n<p><strong>searchModel:<\/strong> array of values which describes the form elements<\/p>\n<ul>\n<li><strong>label<\/strong> The description text of the field<\/li>\n<li><strong>dbname<\/strong> the real database name which is used in the where clause<\/li>\n<li><strong>size<\/strong> the actual size of the element in the form default 15<\/li>\n<li><strong>maxsize<\/strong> the maximal size of the element (maxLength)  attribute. Default 15<\/li>\n<li><strong>defval<\/strong> the default value of the element when constructing the form. Default empty<\/li>\n<li><strong>dtype<\/strong> data type of the element. Values &#8220;S&#8221; (string) or &#8220;N&#8221; (numeric). Default is &#8220;S&#8221;<\/li>\n<li><strong>dopt<\/strong> allowed sequence of options for the condition separated with &#8220;;&#8221;. Here is a list of the possible options:<\/li>\n<\/ul>\n<p>&#8220;eq&#8221; is equal,<br \/>\n&#8220;ne&#8221; is not equal,<br \/>\n&#8220;lt&#8221; is less<br \/>\n&#8220;le&#8221; is less or equal<br \/>\n&#8220;gt&#8221; is greater<br \/>\n&#8220;ge&#8221; is greater or equal<br \/>\n&#8220;bw&#8221; is begins with<br \/>\n&#8220;ew&#8221; is ends with<br \/>\n&#8220;cn&#8221; is contains<\/p>\n<p><strong>capition: <\/strong>(optional) This is the Title of the form. Default value &#8216;Search data where&#8217;.<\/p>\n<p><strong> hideonSearch:  <\/strong>(optional) if set to true the form is hidden after clicking of the button Search. Default is false.<strong><br \/>\n<\/strong><\/p>\n<p><strong>disableClose :<\/strong> (optional)  if set to true the button Close (hide) is disabled. Default is false.<\/p>\n<p><strong>onSearch: <\/strong> (optiona) this function is raised after clicking of button Search and accepts  a string parameter with a ready to use where clause.<\/p>\n<p>By default when constructing a form the flowing  buttons are created:<\/p>\n<p><strong>Search<\/strong>:  This button activates onSearch function with a search string parameter.<\/p>\n<p><strong>Clear<\/strong>: This button clears the entered values.<\/p>\n<p><strong>Close:<\/strong> This button hides a form.<\/p>\n<p>Before to call this function you may want to translate some texts in your language. The default language is English.<\/p>\n<p>This can be done via setLanguage function. Example:<br \/>\n&#8230;<br \/>\nvar mybuttons = [&#8216;Search&#8217;,&#8217;Clear&#8217;,&#8217;Close&#8217; ];<br \/>\nvar myodata = [&#8216;equal&#8217;, &#8216;not equal&#8217;, &#8216;less&#8217;, &#8216;less or equal&#8217;,&#8217;greater&#8217;,&#8217;greater or equal&#8217;, &#8216;begins with&#8217;,&#8217;ends with&#8217;,&#8217;contains&#8217; ];<br \/>\n$.searchdb.setLanguage(mybuttons, myodata);<br \/>\n&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Searchdb is another jQuery plugin. The reason to write this plugin is that I&#8217;m a little be &#8220;lazy&#8221;. Imagine that you have a dynamic table (grid) or report in wich the user will search on many fields with diffrent criteria (equal, less, greater &#8230;). Constructing a form is a first problem. You must write so [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9"}],"collection":[{"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":1,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":799,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/799"}],"wp:attachment":[{"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.trirand.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}