Avatar of erikTsomik
erikTsomik
Flag for United States of America asked on

bootstrapTable

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

BootstrapColdFusion LanguagejQueryWeb DevelopmentJavaScript

Avatar of undefined
Last Comment
_agx_

8/22/2022 - Mon
erikTsomik

ASKER
Any suggestions
Julian Hansen

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?
erikTsomik

ASKER
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Julian Hansen

I posted a couple of questions - do you have answers for those?
_agx_

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.
ASKER CERTIFIED SOLUTION
erikTsomik

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
_agx_

Posting this objection to stop the auto deletion process, since a solution was found and posted
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.