Solved

bootstrapTable

Posted on 2016-10-12
8
90 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 55

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 55

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

829 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