Custom Search and predefined values

Custom Search and predefined values

tijanatijana Posts: 1Questions: 1Answers: 0
edited November 2021 in SearchBuilder

Hi,
I am using this script:

 <script type="text/javascript" SameSite=Strict
        src="https://cdn.datatables.net/v/dt/dt-1.11.3/b-2.0.1/date-1.1.1/r-2.2.9/sc-2.0.5/sb-1.3.0/sp-1.4.0/sl-1.3.3/datatables.min.js"></script>

I am using Datatables and completely custom layout and everything (as customer required) for searching the table/orders.
Each column has related textbox in some custom dropdown.
When I enter text in textbox 1, which is related to a specific column 1, I save that text in database.
When I enter text in textbox 2, which is related to a specific column 2, I save that text in database as well.
It can be number, text, whatever, doesn't matter at the moment.

When I load the application again, I want to have that search text for specific column 1 loaded in textbox 1 and I want table to be filtered already.

Here is a part of my code, I have lots of events afterwards....

.DataTable({
                //'sdom': 'Rlfrtip',
               ** dom: 'Qlfrtip',**
                select: true,
                'colReorder': {
                    'allowReorder': true
                },
                "sAjaxSource": "/orderlines/GetData",
                "bServerSide": true,
                "bProcessing": true,
                "bSearchable": true,
                "scrollX": true,
                orderCellsTop: true,
                scrollY: $(window).innerHeight() - $(".dataTables_scrollHead").height() - $(".list-toolbar").height() - $(".topbar").height() - 30,
                deferRender: true,
               ** searchBuilder: {
                    preDefined: {
                        criteria: [
                            {
                                condition: '=',
                                data: 'OrderId',
                                type: 'num',
                                value: [56]
                            }
                        ]
                    }
                },**
                scroller: {
                    displayBuffer: 10,
                    boundaryScale: 0.75
                },

SO, when the table is loaded and I wanted to see only orders with orderId = 56, nothing actually happens (it is not filtered at all), here is what the ajax is sending to backend [Notice the last bold attributes/parameters]:

GetData?sEcho=4&iColumns=13&sColumns=OrderId%2CProductName%2CProducerName%2CProdAlias%2CRequestedDeliveryDateStringAll%2CIdent%2COrderDateStringAll%2CCompanyName%2CDepartmentName%2CJobname%2CTotalPrice%2CProductionInfo%2CQuantity&iDisplayStart=0&iDisplayLength=60&mDataProp_0=OrderId&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=ProductName&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=ProducerName&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=true&mDataProp_3=ProdAlias&sSearch_3=&bRegex_3=false&bSearchable_3=true&bSortable_3=true&mDataProp_4=RequestedDeliveryDateStringAll&sSearch_4=&bRegex_4=false&bSearchable_4=true&bSortable_4=true&mDataProp_5=Ident&sSearch_5=&bRegex_5=false&bSearchable_5=true&bSortable_5=true&mDataProp_6=OrderDateStringAll&sSearch_6=&bRegex_6=false&bSearchable_6=true&bSortable_6=true&mDataProp_7=CompanyName&sSearch_7=&bRegex_7=false&bSearchable_7=true&bSortable_7=true&mDataProp_8=DepartmentName&sSearch_8=&bRegex_8=false&bSearchable_8=true&bSortable_8=true&mDataProp_9=Jobname&sSearch_9=&bRegex_9=false&bSearchable_9=true&bSortable_9=true&mDataProp_10=TotalPrice&sSearch_10=&bRegex_10=false&bSearchable_10=true&bSortable_10=true&mDataProp_11=ProductionInfo&sSearch_11=&bRegex_11=false&bSearchable_11=true&bSortable_11=true&mDataProp_12=Quantity&sSearch_12=&bRegex_12=false&bSearchable_12=true&bSortable_12=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=desc&iSortingCols=1&**searchBuilder%5Bcriteria%5D%5B0%5D%5Btype%5D=&searchBuilder%5Blogic%5D=AND&_=1637796753853**

I hope my explanation is clear.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    That looks like it should work as the layout looks similar to this example. Are you able to link to your page, or create a test case with that format, please, so we can take a look. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    It's also worth noting that stateSave does deal with remembering the last selections - see example here. Would that work instead?

    Cheers,

    Colin

Sign In or Register to comment.