SearchPane error after ajax.url.load
SearchPane error after ajax.url.load
montoyam
Posts: 568Questions: 136Answers: 5
I have used this code just fine with dataTable that did not have a SearchPane. I am getting an error trying to use it on a dataTable that has one.
$("#varType").change(function () {
typeID = $("#varType option:selected").attr('value');
InvoiceVarianceTable.ajax.url('api/BillingGenerated_Variances?typeID=' + typeID).load();
InvoiceVarianceTable.searchPanes.rebuild();
});
The datatable loads fine initially. I tried it with both a default of zero and one (the two options that typeID can be. When I change the value of the select box, I get the error:
Cannot read property 'searchPanes' of null
I tried adding the searchPanes.rebuild() but that didn't seem to help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Probably due to the ajax request being asynchronous. Use the
callback
function of theajax.url().load()
API to executeInvoiceVarianceTable.searchPanes.rebuild();
.Kevin
i'm not sure if this is the correct syntax (I didn't see any examples of a callback in the documentation) but I am still getting the same error
Are you able to link to your page, or create a test case for us to debug, please? 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.
Cheers,
Colin
I can not provide a link. I have never figured out how to provide a test case...how do I re-construct the api and the controller (this is a MVC project) with not having access to the sql tables externally?
but, it appears to be only a SearchPanes thing. I don't have any issues with this code on another page I have where there are no searchPanes
Hi @montoyam ,
This could be a wide variety of things and without a test case will be hard to debug. Can you please do the following...
Hopefully with this I can provide some insight.
Thanks,
Sandy
wow, I never thought about using the non-minified versions...nice!
So originally I had the searchPanes.rebuild() after the ajax.reload() and it was failing on the xhr call. I changed the order of events as below:
Now, in the Console I see "url load done", but I get an error during the searchPanes.rebuild. But, now, even though I get an error, the xhr finishes and the dataTable is drawn with the new data source. The SearchPane even re-draws even though it never hits my console.log('search panes rebuild done' )
The error is now:
and here is the code where it hangs
i should mention that one result only has 39 rows, one has zero, and one has only 2 rows. So we are not talking about a ton of records (or fields).
The API is
searchPanes.rebuildPane()
so you will need this:You probably don't want to use
ajax.url().load()
followed byajax.reload()
. This is likely going to cause errors as theajax.url().load()
is an outstanding ajax request (no response yet) when you executeajax.reload()
. Remove theBillableItemsTable.ajax.reload();
.Kevin
yes, that got rid of all errors. Thank you!!! I have another project that was giving me similar errors so I will go back and check that one out too (and ask for the still open question in the forum to be closed).
However, I am noticing when I select an option in my pulldown where no records exist, the SearchPane displays 'No SearchPanes'. This is fine, but when I then select an option that has records, the SearchPane displays the records correctly, but then directly below the message 'No SearchPanes' remains.
I built a test case for you to show the issue:
http://live.datatables.net/zoparoye/2/edit
You don't always need to provide us with your full solution. Usually you can use simulated data to recreate the problem. @sandy will likely take a look.
Kevin
ah, so good to know it is not an issue with my data or code as you were able to reproduce the issue. Thanks
Thanks for that test case, Kevin. I may be being dim here, but how can I reproduce the problem? Both those buttons appear to be behaving as expected to me.
Colin
Click the Clear button you will see
No SearchPanes
displayed. Click Reload and the panes reload but theNo SearchPanes
message is not cleared.Kevin
Ah gotcha, thanks for that, I still missed it first time even when following those instructions! I've raised it internally (DD-1923 for my reference) and we'll report back here when there's an update - most likely at the end of this week.
Cheers,
Colin
Hi @montoyam , @kthorngren ,
I've just pushed a fix up for this, a simple check to remove the message if there is a pane to be displayed. Take a look at this example. The styling is a touch off but that is something that we are looking into elsewhere.
This will be available in the next SearchPanes release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.
Thanks,
Sandy
I'm too keen, spotted another issue there - the top row is being removed after the load. Will get that fixed - won't be long!
Turns out that was an easy enough fix too, just a class that I needed to remove at the same point as removing the empty message.
The above example should show this fix also.
Thanks,
Sandy