Solved

bootstrapTable

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

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show confirmation alert in Jquery 14 41
Poster Video HTML 5 Scale to fit video 3 37
Bootstrap on PLNKR 3 13
manage footer size 4 4
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Read about why website design really matters in today's demanding market.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

16 Experts available now in Live!

Get 1:1 Help Now