Solved

bootstrapTable

Posted on 2016-10-12
8
39 Views
Last Modified: 2016-10-16
I am using bootStrap table in conjunction with COldFusion and its all working fine. Now I Need to add a custom toolbar menu item witch will work as a filter.

I can not get this part to work it does not update the tbale onChnage

<div id="toolbar" class="btn-group">


                    <select name="category" id="categoty" class="form-control">
                    	<option value=""> -- Select Category --</option>
                    	<cfoutput query="qGetWikiCategory">
                    		<option value="#categoryid#">#trim(categoryname)#</option>
                    	</cfoutput>
                    </select>



</div>

<div class="col-sm-12 col-md-12 col-lg-12">
            <table id="users" data-height="400" data-side-pagination="server" data-pagination="true" data-search="true"  clickToSelect="true" singleSelect="true" data-single-select="true"
            	data-toolbar="#toolbar"
            	data-show-refresh="true"
            	data-show-toggle="true"
            	<!---data-query-params="queryParams"--->
            	<!---data-response-handler="responseHandler"--->
		 		data-url="/includes/wiki.cfc?method=getWiki"
				data-show-columns="true"
				data-toolbar-align="left"
            >
            </table>
        </div>

Open in new window


$('#users').bootstrapTable({
                method: 'get',
                url: '/includes/wiki.cfc?method=getWiki',
                cache: false,
                height: 400,
                striped: true,
                pagination: true,
                pageSize: 10,
                pageList: [10, 25, 50, 100, 200],
                search: true,
                showColumns: false,
                showRefresh: true,
				singleSelect:true,
                smartDisplay	:true,
                minimumCountColumns: 2,
                clickToSelect: true,
                columns: [
				          {field: 'COUNT',title: 'WIKI #',align: 'right',valign: 'bottom',sortable: false},
						  {field: 'wikiid',title: 'Wiki ID',visible:false},
						  {field: 'name',title: 'Wiki Title',align: 'left',valign: 'middle',sortable: true},
						  {field: 'docUploaded',title: 'File Uploaded',align: 'left',valign: 'middle',sortable: true},
						  {field: 'status',title: 'Status',align: 'left',valign: 'top',sortable: true},
						  {field: 'operate',title: 'Actions',align: 'center',valign: 'middle',clickToSelect: false,formatter: operateFormatter,events: operateEvents}]
            });
    });

	function operateFormatter(value, row, index) {
        return [
            '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
                '<i class="glyphicon glyphicon-edit"></i>',
            '</a>&nbsp;',
            '<a class="remove ml10" href="javascript:void(0)" title="Remove">',
                '<i class="glyphicon glyphicon-remove"></i>',
            '</a>'
        ].join('');
    }

    window.operateEvents = {
        'click .edit': function (e, value, row, index) {
            window.location.href = "addQuestion.cfm?ID=" + +row.wikiid;
        },

        'click .remove': function (e, value, row, index) {
			var conf = "Are you sure you want to delete this wiki?";
			if (conf){
			$.getJSON('/includes/wiki.cfc?method=deleteQuestion&returnformat=json&queryformat=column&_cf_nodebug=true&_cf_nocache=true&ID='+row.wikiid,
				function(d)
				{
					$('#Error').text(d.MESSAGE);
					$('#users').bootstrapTable('refresh');
				});
			}
		}
    };

$("#categoty").change(function(){

		//alert('Hello');
		//alert($(this).val());
		if ($(this).val() > 0){
			$.getJSON('/includes/wiki.cfc?method=getWiki&returnformat=json&queryformat=column&_cf_nodebug=true&_cf_nocache=true&categoryid=' + $(this).val(),
				function(d)
				{

					//$('#Error').text(d.MESSAGE);
				$('#users').bootstrapTable('refresh');
			});

		}

	})

Open in new window


ColdFusion CFC
<cffunction name="getWiki" access="remote" returnformat="plain" returntype="any">
    	<cfargument name="offset" default="0" type="numeric">
        <cfargument name="limit" default="10" type="numeric">
        <cfargument name="order" default="asc" type="string">
        <cfargument name="sort" default="wikiid" type="string">
        <cfargument name="search" default="" type="string" />
        <cfargument name="categoryid" default="" type="string" />

     	<cfquery name="getWiki" datasource="#request.datasource#">
        	WITH Rows AS
            (
				SELECT	 W.wikiid,W.name,W.wikiText,CASE WHEN W.status = 1 THEN 'Active' ELSE 'Inactive' END as status,W.docUploaded,
						 ROW_NUMBER() OVER (ORDER BY #sort# #order#) [Row]
                FROM wiki W
                inner join wikiCategory WC on WC.categoryID = W.wiki_categoryID
                WHERE 1=1
				<cfif Search NEQ "">
                    and
                    W.wikiid like '%#arguments.Search#%' OR W.name like '%#arguments.Search#%' OR W.wikiText like '%#arguments.Search#%'
                </cfif>
                <cfif arguments.categoryid neq "">
                	and WC.categoryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.categoryid#">
                </cfif>
             )
                SELECT
                      *
                FROM
                     Rows
                WHERE Row >= #offset+1# and Row <= #offset+limit#
        </cfquery>



        <cfquery name="qCount" datasource="#request.datasource#">
        	SELECT COUNT(*) as total
            FROM wiki W
            inner join wikiCategory WC on WC.categoryID = W.wiki_categoryID
            WHERE 1=1
            <cfif Search NEQ "">
                and
                W.wikiid like '%#arguments.Search#%' OR name like '%#arguments.Search#%' OR wikiText like '%#arguments.Search#%'
            </cfif>
             <cfif arguments.categoryid neq "">
                	and WC.categoryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.categoryid#">
                </cfif>
        </cfquery>

        <cfset resultStruct = Structnew() />
      	<cfset resultStuct["total"] = qCount.total />
        <cfset resultStuct["rows"] = ArrayNew(1) />
      	<cfset count = 1/>
      	<cfloop query="getWiki" >
            <cfset resultStuct["rows"][count]['COUNT'] =  Count />
			<cfset resultStuct["rows"][count]['wikiid'] =  getWiki.wikiid />
			<cfset resultStuct["rows"][count]['name'] =  getWiki.name />
            <cfset resultStuct["rows"][count]['wikiText'] =  getWiki.wikiText />
            <cfset resultStuct["rows"][count]['status'] =  getWiki.status />
             <cfset resultStuct["rows"][count]['docUploaded'] =  getWiki.docUploaded />
            <cfset Count = Count + 1/>
      	</cfloop>

      	<cfreturn SerializeJSON(resultStuct) />
    </cffunction>

Open in new window

0
Comment
Question by:erikTsomik
  • 3
  • 2
  • 2
8 Comments
 
LVL 19

Author Comment

by:erikTsomik
ID: 41841324
Any suggestions
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41841678
1. Is the $.getJSON firing - have you checked the console to see if it is and what it is returning
2. What does the $.getJSON do - you don't appear to be using the return'd value which begs the question why you are using $.getJSON and not just $.get

I tried to look at the docs for bootstraptable but the site is not responding currently - but I am going to assume that the refresh action is meant to re-get the data - do you see any evidence of this in the console?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 41841810
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41841840
I posted a couple of questions - do you have answers for those?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41842137
erikTsomik - Did you mean to hit "Delete Question"? Seems like you found a solution. If so it should be added to the archives to help the next person with the same problem.
0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 0 total points
ID: 41842167
The solution

$("#categoty").change(function(){
                  $('#users').bootstrapTable('refresh',{query: {categoryid: $(this).val()}});
            })
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41842681
Posting this objection to stop the auto deletion process, since a solution was found and posted
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now